Is it possible to document dynamic query parameter using Fastify on Swagger, that allow client to pass the param value inside text field on Swagger UI using Swagger v1.0.0?, in my case is to input dynamic value of conversationId
parameter.
Here is my swagger.js file in config folder.
exports.options = {
routePrefix: '/documentation',
exposeRoute: true,
swagger: {
info: {
title: 'Wrapper API',
description: 'Building a wrapper api',
version: '1.0.0'
},
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
host: 'localhost:3000',
schemes: [
'http',
'https'
],
consumes: ['application/json'],
produces: ['application/json'],
}
}
+ Here is my route
const healthBotController = require('../controllers/healthBotWrapperController')
const routes = [
{
method: 'GET',
url: '/',
handler: healthBotController.getEndpoints
},
]
module.exports = routes;
I tried to search and read document but I couldn't find solution to my problem yet.
Thank you in advanced.
To add the query parameters in swagger, you need to define a JSON Schema in the route configuration:
const fastify = require('fastify')()
fastify.register(require('fastify-swagger'), {
routePrefix: '/documentation',
exposeRoute: true,
swagger: {
info: {
title: 'Wrapper API',
description: 'Building a wrapper api',
version: '1.0.0'
},
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
host: 'localhost:3000',
schemes: [
'http',
'https'
],
consumes: ['application/json'],
produces: ['application/json'],
securityDefinitions: {
ApiToken: {
description: 'Authorization header token, sample: "Bearer #TOKEN#"',
type: 'apiKey',
name: 'Authorization',
in: 'header'
},
Oauth2Token: {
description: 'OAUTH2',
type: 'oauth2',
flow: 'accessCode',
authorizationUrl: 'https://example.com/oauth/authorize',
tokenUrl: 'https://example.com/oauth/token',
scopes: {
read: 'Grants read access',
foo: 'Grants foao scope'
}
}
}
}
})
fastify.route({
method: 'GET',
url: '/',
schema: {
security: [{ ApiToken: [], Oauth2Token: [] }],
querystring: {
foo: { type: 'number' },
bar: { type: 'string' }
}
},
handler: function foo () {}
})
fastify.listen(8080)
Then in http://localhost:8080/documentation you will see: