Adonis Swagger
Installation
```
adonis install adonis-swagger
```
Configuration
- Register
SwaggerProvider
instart/app.js
:
...
'adonis-swagger/providers/SwaggerProvider'
```
- Other configuration please update the
config/swagger.js
file.
Sample Usage
- Add new route
- Create TestController using command adonis make:controller Test
/**
* @swagger
* /api/hello:
* get:
* tags:
* - Test
* summary: Sample API
* parameters:
* - name: name
* description: Name of the user
* in: query
* required: false
* type: string
* responses:
* 200:
* description: Send hello message
* example:
* message: Hello Guess
*/
async hello({ request, response }) {
const name = request.input('name', 'Guess')
response.send({ message: 'Hello ' + name })
}
}
module.exports = TestController
```
- You can also define the schema in the Models
- Or create a separate file containing documentation from the APIs in either JS or YAML formats, sample structure:
- Other sample in YAML and JS format please refer this link
For detail usage, please check the swagger specification in this linkSwaggerSpec.
Command List
Command | Description
:-----------------------------|:-----------
adonis swagger:export
| Export config file & swagger-ui assets
adonis swagger:remove
| Remove config file & swagger-ui assets
adonis swagger:remove-docs
| Remove swagger-ui only
Dependencies
Thanks
Special thanks to the creator(s) of AdonisJSAdonisJS for creating such a great framework.