-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wildcard paths fails Swagger validation #773
Comments
Seems like a bug in fastify-swagger. When converting the URL, the plugin replaces the "*" param with {wildcard} here, but it doesn't do the same for the parameters schema. Two potential solutions:
Since the conversion of the URL seems to be the expected behavior and changing it could break current behavior, the second option seems best. However, it might break code for those aware of this behavior and defining the param schema for "/id/:id/star/*" like:
I'm willing to work on this if the maintainers check this issue. |
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
I don't think we can change the actual schema of the route, if that's what you are asking. Anything that happens only in openapi land... it's ok. |
Prerequisites
Fastify version
4.25.0
Plugin version
8.12.1
Node.js version
18.16.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.1.1
Description
We are running into a issue when creating a schema and Swagger documentation for a wildcard route.
When creating a route with a wildcard in the path, the swagger schema produced does not pass the validation when used on https://editor.swagger.io/. The problem is that URL does not match with the path parameters in the schema because the
*
has been renamed towildcard
.We notice this when we started to validate our Swagger schema with https://editor.swagger.io/ and the following errors occurred
We have also created a small repo that shows the issue https://github.com/Milkywire/fastify-swagger-wildcard
Steps to Reproduce
Setup a route with a wildcard like this
The documentation produced by @fastify/swagger will replace the
*
with{wildcard}
in the path of the endpoint. So the documentation will look like thisCopy the JSON into https://editor.swagger.io/ and you will get the following errors
Expected Behavior
The path in the documentation matches the path specified in fastify.
Potential Workaround
A potential workaround that we looked at was to replace the star in the endpoint schema with “wildcard” to align with the documentation. This works okey when using JavaScript we just have to remember that we still need to use the “*” when getting the value from
request.params
and notwildcard
.However in our setup using TypeScript and TypeBox for our schema setup this is not an option since the
request.params
object is limited to the fields you define in the schema.The text was updated successfully, but these errors were encountered: