'Fastify Swagger, add tag and description to fastify route
I'm using fastify 3.28.0 (plus fastify-swagger plugin) with typescript 4.6.2, and I'd like to add tags, description and summary inside every route.
From docs: fastify swagger It would be possibile to add description, tags and summary to every route.
But I'm not able to do it because the definition of the schema does not provide them:
export interface FastifySchema {
body?: unknown;
querystring?: unknown;
params?: unknown;
headers?: unknown;
response?: unknown;
}
So in this case I don't know how to define them inside fastify routes:
const userRoutes: FastifyPluginCallback = (fastify, _opts, done) => {
const findRoute: RouteOptions = {
method: 'GET',
url: '/:username',
schema: {
params: schemaParams,
response: {
200: schema
}
},
handler: (request: FastifyRequest<{
Params: UserRequestFindParams,
}>, reply) => {
const user = find(request.params.username)
reply.send(user)
}
}
fastify.route(findRoute)
done()
}
*** UPDATE
I've just discovered that a new version of fastify-swagger has been released (fastify-swagger has been replaced by @fastify/swagger). With the new version all the properties mentioned above are available.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|