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
{{ message }}
Repository navigation
Dynamically computed meta with defineRouteMeta() #2641
Seems like I cannot import any variables inside the openAPI object, it would be very useful to be able to do so since I for example this api returns a value from DB
Additional context
No response
Logs
No response
Reacted by Jimmy Guzman, Semjon Geist, Michael Lai, Ttou, Niklas Huthmann, Vladislav Diachenko and John Strickler
Additional info: defineRouteMeta also doesn't work when called from within another function. I encountered this when trying to define a function that would accept input schemas and set the route meta based on the input schema as well as perform input validation in the page handler. I suspect this is caused by parsing route meta using an AST rather than evaluating the code directly.
As an alternative, I'd be interested if it would be possible to define route meta using the event handler object format:
I think it's a good idea, and without this meta-definition, the entire OpenAPI documentation generation wouldn't make sense. Alternatively, everything could be generated automatically through TypeScript.
Type 'SchemaObject | SchemaObject | ReferenceObject' is not assignable to type 'ReferenceObject | SchemaObject | undefined'.
Type 'SchemaObject' is not assignable to type 'ReferenceObject | SchemaObject | undefined'.
Type 'SchemaObject' is not assignable to type '({ [key: `x-${string}`]: any; discriminator?: DiscriminatorObject | undefined; xml?: XMLObject | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 15 more ...; required?: string[] | undefined; } & StringSubtype) | ... 6 more ... | ({ ...; } & { ...; })'.
Type 'SchemaObject' is not assignable to type '{ [key: `x-${string}`]: any; discriminator?: DiscriminatorObject | undefined; xml?: XMLObject | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 15 more ...; required?: string[] | undefined; } & ArraySubtype'.
Type 'SchemaObject' is not assignable to type '{ [key: `x-${string}`]: any; discriminator?: DiscriminatorObject | undefined; xml?: XMLObject | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 15 more ...; required?: string[] | undefined; }'.
Types of property 'oneOf' are incompatible.
Type '(SchemaObject | ReferenceObject)[] | undefined' is not assignable to type '(ReferenceObject | SchemaObject)[] | undefined'.
Type '(SchemaObject | ReferenceObject)[]' is not assignable to type '(ReferenceObject | SchemaObject)[]'.
Type 'SchemaObject | ReferenceObject' is not assignable to type 'ReferenceObject | SchemaObject'.
Type 'SchemaObject' is not assignable to type 'ReferenceObject | SchemaObject'.
Type 'SchemaObject' is not assignable to type '({ [key: `x-${string}`]: any; discriminator?: DiscriminatorObject | undefined; xml?: XMLObject | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 15 more ...; required?: string[] | undefined; } & StringSubtype) | ... 6 more ... | ({ ...; } & { ...; })'.
Type 'SchemaObject' is not assignable to type '{ [key: `x-${string}`]: any; discriminator?: DiscriminatorObject | undefined; xml?: XMLObject | undefined; externalDocs?: ExternalDocumentationObject | undefined; ... 15 more ...; required?: string[] | undefined; } & ArraySubtype'.
Type 'SchemaObject' is not assignable to type 'ArraySubtype'.
Types of property 'type' are incompatible.
Type 'SchemaObjectType | SchemaObjectType[] | undefined' is not assignable to type '"array" | ["array", "null"]'.
Type 'undefined' is not assignable to type '"array" | ["array", "null"]'.ts(2322)
trying to use { createSchema, extendZodWithOpenApi } from 'zod-openapi'
Activity
michaelkplai commentedon Nov 1, 2024
Additional info:
defineRouteMetaalso doesn't work when called from within another function. I encountered this when trying to define a function that would accept input schemas and set the route meta based on the input schema as well as perform input validation in the page handler. I suspect this is caused by parsing route meta using an AST rather than evaluating the code directly.As an alternative, I'd be interested if it would be possible to define route meta using the event handler object format:
Ttou commentedon Nov 17, 2024
when i use zod-openapi to generate schema, defineRouteMeta can't recognize
pi0 commentedon Nov 18, 2024
Currently,
defineRouteMetais an experimental idea and only accepts static inlined meta.[-]defineRouteMeta not working with imported values[/-][+]Dynamically computed meta with `defineRouteMeta()`[/+]GentleGhostCoder commentedon Nov 18, 2024
I think it's a good idea, and without this meta-definition, the entire OpenAPI documentation generation wouldn't make sense. Alternatively, everything could be generated automatically through TypeScript.
AkarinServer commentedon Nov 29, 2024
I have same problem with you. I think it is very necessary to support dynamic variables for defineRouteMeta
pi0 commentedon Jan 7, 2025
Moving to #2974
alex-eri commentedon Feb 14, 2025
I have typescript error
trying to use { createSchema, extendZodWithOpenApi } from 'zod-openapi'