You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{extendZodWithOpenApi}from"@asteasolutions/zod-to-openapi";import{z}from"zod";extendZodWithOpenApi(z);constBodySchema=z.object({name: z.string()}).openapi({title: "User",description: "Required user information"});constQuerySchema=BodySchema.extend({age: z.number().optional()}).openapi({title: "User details",description: "Optional user information",});constParamsSchema=z.object({id: z.string()});constResponseSchema=z.object({success: z.boolean()});export{BodySchema,ParamsSchema,QuerySchema,ResponseSchema};
As of version 5, trying to extend the BodySchema (which already utilized openapi) fails with:
Exception during run: TypeError: Cannot read properties of undefined (reading 'extendedFrom')
at ZodObject.result.extend (/Users/~/express-zod-openapi-autogen/node_modules/@asteasolutions/zod-to-openapi/dist/index.cjs:84:106)
This may be intended behavior but I did not find it documented and it seemed to work prior to version 5. I have tested that this is still an issue in v6 and v7.
The problem seems to have been introduced to changes to the extendZodWithOpenApi function introduced here in the src/zod-extensions.ts file
Prior to this change, schemas could be extended and the new values declared in the openapi argument would override the originals.
The text was updated successfully, but these errors were encountered:
Take the following code example
As of version 5, trying to extend the BodySchema (which already utilized openapi) fails with:
This may be intended behavior but I did not find it documented and it seemed to work prior to version 5. I have tested that this is still an issue in v6 and v7.
The problem seems to have been introduced to changes to the extendZodWithOpenApi function introduced here in the src/zod-extensions.ts file
Prior to this change, schemas could be extended and the new values declared in the openapi argument would override the originals.
The text was updated successfully, but these errors were encountered: