๐ Feature Proposal
Implement Swagger documentation generator for routes defined using fastify-swagger.
Motivation
A good API is well documented. To facilitate the writing of documentation, we are going to set up the Swagger documentation generator for routes.
Example
The developer should be able to choose if he wants to set up swagger or not in http.js
config file:
/*
|--------------------------------------------------------------------------
| No swagger
|--------------------------------------------------------------------------
|
| This value defines if HttpKernel will set Swagger plugin or not.
|
*/
noSwagger: false
The developer should be able to set the base swagger configurations in http.js
config file:
/*
|--------------------------------------------------------------------------
| Swagger
|--------------------------------------------------------------------------
|
| Setup your base Swagger configuration.
|
*/
swagger: {
info: {
title: 'Test swagger',
description: 'Testing the Athenna swagger API',
version: '0.1.0'
},
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
host: 'localhost',
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json'],
tags: [
{ name: 'user', description: 'User related end-points' },
{ name: 'code', description: 'Code related end-points' }
],
definitions: {
User: {
type: 'object',
required: ['id', 'email'],
properties: {
id: { type: 'string', format: 'uuid' },
firstName: { type: 'string' },
lastName: { type: 'string' },
email: {type: 'string', format: 'email' }
}
}
},
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'apiKey',
in: 'header'
}
}
}
The developer should be able to set up the swagger schema for each route:
Route.get('/', ({ response }) => response.status(200).send({ hello: 'world' })).swaggerOptions({
schema: {
description: 'Hello world',
tags: ['hello'],
response: {
200: {
description: 'Successful response',
type: 'object',
properties: {
hello: { type: 'string' }
},
},
},
}
})
Or using a more simple configuration with builder pattern:
Route.get('/', ({ response }) => response.status(200).send({ hello: 'world' }))
.description('Hello world')
.tags('hello')
.response(200, { description: 'Successful response', type: 'object', properties: { hello: { type: 'string' } } })