Replies: 1 comment
|
I'm running into similar crashes. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello, I'm using the
zod-to-openapiextension to generate OpenAPI documentation from my Zod schemas. I'm trying to create multiple named examples for a single request/response schema to illustrate different scenarios, such as success, failure, and processing states.I want to define these examples within the schema itself using the
.openapi()method, but I encountered two distinct issues.Example Schema:
Here’s a simplified version of the schema I’m working with, using dummy data:
Problem 1: TypeScript Types Not Recognizing Named Examples
When I attempt to use named examples within the
.openapi()method (e.g.,OrderSuccess,OrderFailed,OrderProcessing), TypeScript doesn’t recognize them correctly. This approach results in type errors, making it challenging to compile the project.To overcome this, I switched to using unnamed examples (as shown in the code above), which resolves the type issues, but leads to the second problem.
Problem 2: OpenAPI Documentation Generation Crashes
Although using unnamed examples resolves the type issues, it causes the OpenAPI documentation generation to crash with the following error:
node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:84 : (_e = this._def.openapi) === null || _e === void 0 ? void 0 : _e._internal.extendedFrom, ^ TypeError: Cannot read properties of undefined (reading 'extendedFrom') at ZodObject.result.extendIt seems that the OpenAPI generator might not be handling the unnamed examples correctly, leading to this crash.
Questions:
For Problem 1: Am I structuring the
examplesfield correctly within the.openapi()method? Is there a recommended way to define multiple named examples in a way that TypeScript can recognize them without causing type errors?For Problem 2: Is there a known limitation or bug that causes the OpenAPI documentation generation to crash when using unnamed examples? If so, is there an alternative approach I should be using to avoid this issue?
Any guidance or examples of how to correctly structure these examples while maintaining TypeScript compatibility and ensuring the OpenAPI documentation generation works would be greatly appreciated!
Thank you in advance for your help!
All reactions