Docs
No description available
Install / Use
/learn @appliedblockchain/DocsREADME
<h1 align="center">
API Documentation Creator
</h1>
Installation
- Add as a package dependency
$ npm install ab-docs --save
- Require it in your code
const { withDocs } = require('ab-docs')
- Create a swagger specification to pass into the function. A base specification should be provided with an info object (containing at least the title and version strings) and any other global descriptions.
module.exports = {
baseSpec: {
info: {
title: name,
description: 'API description',
version
},
basePath: '/',
tags: [
{
name: 'tag name',
description: 'tag description'
},
]
},
specOptions: {
defaultResponses: {}
}
}
- Use
withDocsfunction like so:
const { withDocs } = require('ab-docs')
withDocs(router, routes, baseSpec, specOptions)
Accessing API Documentation
Endpoint: /docs
Example endpoint structure:
{
method: 'get',
path: '/endpoint',
validate: {
type: 'json',
body: Joi.object({
property: 'value'
})
output: {
200: {
body: Joi.object({
property: 'value'
}).description('...')
},
404: {
body: Joi.object({
errors: Joi.array().items(
{
property: 'value'
}
)
}).description('...')
}
}
},
meta: {
swagger: {
summary: '...',
description: '...',
tags: [ 'refer to existing tags in config file' ]
}
},
handler: ...
}
