Closed ivan-tymoshenko closed 10 months ago
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 https://github.com/fastify/fastify-swagger/pull/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: