1.2.0 • Published 6 years ago

@hapiness/swag v1.2.0

Weekly downloads
-
License
SEE LICENSE IN ht...
Repository
github
Last release
6 years ago

Swag Module

Swag module for the Hapiness.

Table of contents

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 })
]);

Back to top

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

Back to top

Contributing

To set up your development environment:

  1. clone the repo to your workspace,
  2. in the shell cd to the main folder,
  3. hit npm or yarn install,
  4. 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.

Back to top

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

Back to top

Maintainers

Back to top

License

Copyright (c) 2017 Hapiness Licensed under the MIT license.

Back to top