-
-
Notifications
You must be signed in to change notification settings - Fork 638
Description
Describe the feature
I would like to propose an alternative way to sole issue #2974 by accepting a field on defineRouteMeta which can be parsed via custom processors (eg, z.toJSONSchema(schema)
) and populated into openAPI global schemas.
Currently, there is no way to use a validator like Zod to define the structure of event handler inputs and re-use the schema in the OpenAPI definition within the route file itself. This is because defineRouteMeta is statically compiled, and therefor never sees the value. As a result, duplication of code is required in definitnng both a validator as well as a JSON schema.
Ideally there would be some way to export or define Zod (or other validators) objects in an event handler to automatically be converted into JSON Schema to define responses, request body and query params in OpenAPI via your validation code.
I would like to spark a conversation around ideal implementation for this. At minimum giving us a way to define objects into the global schema namespace would be helpful but not ideal.
Perhaps a better solution could be a new composable, such as defineSchema or defineValidation?
Looking forward to contributing for this once we have a clear direction.
Additional information
- Would you be willing to help implement this feature?