-
-
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
Automatically generate path params definition #750
Comments
I am not sure. If we do this, the swagger could be correct. But on the other hand, path params schema is not effected by this. |
Sorry, I don't undersand what do you mean |
fastify.get('/example/{param}', {schema: { params: {} /* what? */ } }, async (request, reply) => {}) |
Oh, I see. Can we resolve it on a fastify level? |
idk. I would personally expect that schema gets validated against the path. |
@Uzlopak I don't understand |
const paramsJsonSchema = {
type: 'object',
required: [
'par1', 'par2'
],
properties: {
par1: { type: 'string' },
par2: { type: 'number' }
},
additionalProperties: false
}
fastify.get('/example/{par1}/{par2}', {schema: paramsJsonSchema }, async (request, reply) => {}) // OK
fastify.get('/example/{par1}/{par2}/{invalid}', {schema: paramsJsonSchema }, async (request, reply) => {}) // ERROR: Did not found 'invalid' in schema
fastify.get('/example/{par1}/{par3}', {schema: paramsJsonSchema }, async (request, reply) => {}) // ERROR: Missing parameter 'par2' |
I would say, let's generate default param schema only if user doesn't specify a schema for param at all. If there is something, even with missing params like in your example, we should not modify it. |
I agree. |
This would be amazing to have |
I'd like to pick up this. |
go for it! |
I think this #761 could be a good way. Let me know otherwise. I'm open to suggestions. |
Prerequisites
Issue
It would be nice if @fastify/swagger would generate a default schema for path params.
Something like this:
Instead of this:
The text was updated successfully, but these errors were encountered: