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
I am encountering a challenge while setting up Bearer token authentication with validation using Zod in conjunction with the library’s createRoute function. While the documentation provides guidance on registering the security scheme and defining security for specific routes, there are some gaps when it comes to header validation and avoiding overlapping header definitions.
When I want to enforce Zod validation to ensure the presence of the Authorization header and validate its format, I attempt to add the following to the request configuration:
request: {headers: z.object({authorization: z.string().min(4),// Example to ensure that a bearer token is provided in the header}),
...routeConfig.request,},
The Problem:
When I include the above code for request.headers, the generated OpenAPI documentation shows two overlapping header definitions:
One from the security configuration (Bearer).
Another from the explicit headers validation added using z.object.
This creates redundancy in the documentation and could confuse
Expected Behavior:
A straightforward way to validate the presence and format of the Authorization header using Zod.
Ensure the validation logic is reflected in the OpenAPI documentation.
Avoid duplication or overlapping definitions for headers in the documentation when combining the security property and request.headers.
Questions:
Is there an officially recommended approach to integrate Zod validation for headers while leveraging security schemes without causing overlaps in the documentation?
Could the library support a default header validator for registered securitySchemes, so manual addition of request.headers becomes unnecessary?
Is there any existing support for enhancing the security definition to include such validation directly?
Thank you for your assistance and guidance! I am looking forward to your feedback. 😊
The text was updated successfully, but these errors were encountered:
Hello,
I am encountering a challenge while setting up Bearer token authentication with validation using Zod in conjunction with the library’s createRoute function. While the documentation provides guidance on registering the security scheme and defining security for specific routes, there are some gaps when it comes to header validation and avoiding overlapping header definitions.
I am setting up authorization as follows:
The Problem:
This creates redundancy in the documentation and could confuse
Expected Behavior:
Questions:
Thank you for your assistance and guidance! I am looking forward to your feedback. 😊
The text was updated successfully, but these errors were encountered: