@hapiness/swag
v1.2.0
Published
Generate swag documentation for Hapiness' components
Downloads
6
Maintainers
Readme
Swag Module
Swag
module for the Hapiness.
Table of contents
- Using your module inside Hapiness application
- Add documentation to your routes
- Contributing
- Change History
- Maintainers
- License
Using your module inside Hapiness application
yarn
or npm
it in your package.json
$ npm install --save @hapiness/core @hapiness/swag rxjs
or
$ yarn add @hapiness/core @hapiness/swag rxjs
"dependencies": {
"@hapiness/core": "^1.2.2",
"@hapiness/swag": "^1.1.0",
//...
}
//...
import SwagModule
from the library
import { Hapiness, HapinessModule, HttpServerExt, Route, OnGet } from '@hapiness/core';
import { SwagModule } from '@hapiness/swag';
@Route({
method: 'GET',
path: '/todo',
config: {
plugins: {
'hapi-swagger': {
'x-custom-values': {
'scope': 'todo.read',
},
'x-toto': 'tata'
}
},
description: 'Get todo',
notes: 'Returns todo item',
tags: ['api', 'todo']
}
})
class GetTodo implements OnGet {
onGet(request, reply) {
reply('I am a todo');
}
}
@HapinessModule({
version: '1.0.0',
imports: [
SwagModule.setConfig({ info: { title: 'Todo Service' } })
],
declarations: [ GetTodo ]
})
class HapinessModuleApp {
}
Hapiness.bootstrap(HapinessModuleApp, [
HttpServerExt.setConfig({ host: '0.0.0.0', port: 4443 })
]);
Add documentation to your routes
To get a complete list of allowed configuration for your route, you can follow what has been there hapi-swagger
To get the JSON format of your documentation, just go to the url YOUR_SERVICE_HOST:YOUR_SERVICE_PORT/swagger.json
To access the swagger interface of your documented endpoints, just go to the url YOUR_SERVICE_HOST:YOUR_SERVICE_PORT/documentation
and you will be able to test them
Contributing
To set up your development environment:
- clone the repo to your workspace,
- in the shell
cd
to the main folder, - hit
npm or yarn install
, - run
npm or yarn run test
.- It will lint the code and execute all tests.
- The test coverage report can be viewed from
./coverage/lcov-report/index.html
.
Change History
- v1.1.0 (2017-11-20)
- Latest packages' versions.
- Documentation.
- Change packaging process.
- v1.0.0 (2017-10-27)
- Add possibility to have
x-*
as values - Documentation
- First stable version
- Add possibility to have
Maintainers
License
Copyright (c) 2017 Hapiness Licensed under the MIT license.