question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Zod type ZodNonEmptyArray is unsupported by OpenAPI

See original GitHub issue

If output uses z.array().notempty, Open API won’t start with the message Zod type ZodNonEmptyArray is unsupported ZodUndefined also does not work express-zod-api version is 2.3.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kirdkcommented, Aug 20, 2021

@kirdk , please upgrade to version 2.3.2 I’ve just released and make sure that your package manager installs Zod version 3.7.2 as the dependency. I believe this should fix your issue with ZodNonEmptyArray.

Use if ('field' in object) type narrowing syntax instead of ZodUndefined. I believe this should fix your issue with ZodUnion.

I’m closing this issue. In case your issue persist please open another one with detailed code samples. Thank you for your feedback.

@RobinTail, using ‘in’ is not an elegant solution, because the whole code should be wrapped just because we using one union with an optional field. We already wrapping the access to the field value, because it can be undefined. Additional wrapping just to get it works with Openapi it’s not awesome 😃 Thanks anyway! We will try to reopen the issue after the project deadline and prepare a sample.

1reaction
kirdkcommented, Aug 20, 2021

@kirdk , Regarding ZodNonEmptyArray issue.

I figured out that there is no such class in Zod 3.7.x, though it existed in 3.6.x. But express-zod-api is using 3.7.1 since version 2.1.0.

The fact that you are experiencing this issue with the latest version of express-zod-api might mean that for some reason you have incorrect version of Zod installed as the express-zod-api dependency.

Please check out this PR with a test that covers the z.array().nonempty() case, additional information and recommendations:

#105

Dear @RobinTail , while we prepared a project to reproduce the issue you solved it). I do confirm that problem was in zod dependency. After the update, the issue is solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

colinhacks/zod: TypeScript-first schema validation ... - GitHub
With Zod, you declare a validator once and Zod will automatically infer the static TypeScript type. It's easy to compose simpler types into...
Read more >
asteasolutions/zod-to-openapi - npm
Start using @asteasolutions/zod-to-openapi in your project by running `npm i ... Zod schema types. Supported types; Unsupported types.
Read more >
Validate All the Things with Zod - Atomic Spin
Zod allows us to define a schema, infer types from that schema, then validate based on that schema. If the data doesn't match...
Read more >
TypeScript-First Schema Validation with Static Type Inference
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a...
Read more >
io-ts vs zod : r/typescript - Reddit
And 3.1 still lacks adoption. We are on a journey from generating code from openapi specs for our self. It went from generating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found