koa-spec

0.6.5 • Public • Published

koa-spec

npm version Build Status Coverage Status Code Climate Code Documentation Issue Count Dependency Status npm downloads GitHub Issues License Cat Gifs

Installation

$ npm install --save koa-spec ⏎

Examples

Various examples can be found in the /examples directory and executed like this:

$ node examples/simple/app.js ⏎

Basic Example

This is the most simple example showing basic routing (i.e. no parameter or response validation).

(data/)api.yaml

swagger: '2.0'
info:
  version: 0.0.1
  title: Simple.
paths:
  /:
    get:
      x-controller: IndexController
      x-controller-method: get
      responses:
        200:
          description: OK

(controllers/)IndexController.js

'use strict';
 
module.exports.get = function* () {
  this.body = { index : 'Hello koa-spec!' };
};

app.js

'use strict';
 
const koa = require('koa');
const koaspec = require('koa-spec');
 
const app = koa();
 
const spec = koaspec('data/api.yaml');
const router = spec.router();
app.use(router.routes());
 
app.listen(8000);

Result

$ curl localhost:8000 ⏎
{
  "index" : "Hello koa-spec!"
}

Features/Roadmap

  • YAML Parsing
  • $ref Resolving
    • local
    • relative
    • remote
    • circular
  • Routing
  • Validation
    • Required
    • Default values
      • Body parameter
      • Query string
      • Headers
    • x-nullable
    • Parameter
      • Sources
        • Header
        • Path
        • Query
        • Body
        • FormData
    • Response
      • Header
      • Body
    • Types
      • Integer
        • int32 (int)
        • int64 (long)
      • Number
        • float
        • double
      • String
        • string
        • byte
        • binary
        • UUID (V1/V4)
        • ISBN (10/13)
        • date (ISO8601)
        • date-time (ISO8601)
      • Boolean
        • boolean
    • Produces
    • Consumes
  • Error-Handling (throw early, throw often)
  • Spread out strictMode usage

Package Sidebar

Install

npm i koa-spec

Weekly Downloads

19

Version

0.6.5

License

Apache-2.0

Last publish

Collaborators

  • luxe-admin