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'; moduleexports { thisbody = index : 'Hello koa-spec!' ;};
app.js
'use strict'; const koa = ;const koaspec = ; const app = ; const spec = ;const router = spec;app; app;
Result
$ curl localhost:8000 ⏎
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
- Sources
- 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
- Integer
- Produces
- Consumes
- Error-Handling (throw early, throw often)
- Spread out
strictMode
usage