koa-spec
v0.6.5
Published
OpenAPI Specification koa middleware.
Downloads
6
Maintainers
Readme
koa-spec
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
- [x] YAML Parsing
- [x]
$ref
Resolving- [x] local
- [ ] relative
- [ ] remote
- [x] circular
- [x] Routing
- [x] Validation
- [x] Required
- [x] Default values
- [x] Body parameter
- [x] Query string
- [ ] Headers
- [x] x-nullable
- [ ] Parameter
- [ ] Sources
- [ ] Header
- [x] Path
- [x] Query
- [x] Body
- [x] FormData
- [ ] Sources
- [ ] Response
- [ ] Header
- [ ] Body
- [ ] Types
- [x] Integer
- [x] int32 (int)
- [x] int64 (long)
- [x] Number
- [x] float
- [x] double
- [ ] String
- [x] string
- [ ] byte
- [ ] binary
- [x] UUID (V1/V4)
- [x] ISBN (10/13)
- [ ] date (ISO8601)
- [x] date-time (ISO8601)
- [x] Boolean
- [x] boolean
- [x] Integer
- [ ] Produces
- [ ] Consumes
- [ ] Error-Handling (throw early, throw often)
- [ ] Spread out
strictMode
usage