Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 1.96 KB

README.md

File metadata and controls

84 lines (62 loc) · 1.96 KB

joi-router-swagger-docs

A node module for generating Swagger 2.0 JSON definitions from existing koa-joi-router routes.

Aiming to be a replacement for koa-resourcer-docs which can take advantage of various Swagger 2.0 tools for generating client libraries, test suites, AWS Lambda/serverless, etc.

This is very WIP (many things missing or broken), and thus is not available on npm yet.

Example

const SwaggerAPI = require('joi-router-swagger-docs').SwaggerAPI;
const Router = require('koa-joi-router');
const Joi = Router.Joi;
const router = router();

router.get('/signup', {
  validate: {
    type: 'json',
    body: {
      name: Joi.string().max(100).description('new user name')
    },
    output: {
      200: {
        body: {
          userId: Joi.string().description('newly created user id')
        }
      }
    }
  },
  handler: function*() {
    // ...
  }
});

swaggerAPI.addJoiRouter(router);

let spec = swaggerAPI.generateSpec({
  info: {
    title: 'Example API',
    description: 'API for creating and editing examples',
    version: '1.1'
  },
  basePath: '/api/v1'
});

console.log(JSON.stringify(spec, null, '  '));

API

new SwaggerAPI()

Creates a new SwaggerAPI instance.

swaggerAPI.addJoiRouter(router, options)

Add a joi-router instance to the API. The router should already have all its routes set up before calling this method (which pulls the route definitions from the router's .routes property).

Options:

  • prefix: Prefix to add to Swagger path

swaggerAPI.generateSpec(baseSpec)

Create a Swagger specification for this API. A base specification should be provided with an info object (containing at least the title and version strings) and any other global descriptions.

Sponsored by

Pebble Technology!

License

MIT