0.0.0-alpha.11 • Published 5 years ago

listener-from-oas3 v0.0.0-alpha.11

Weekly downloads
18
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage

Be advised: this project is currently at Major version zero. Per the semantic versioning spec: "Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable."

Javascript library which generates a native http server listener from a v3 open api spec

Installation

NPM

npm install --save listener-from-oas3

Yarn

yarn add listener-from-oas3

Handlers

The signature for handlers is async myHandler(ctx)

The ctx object is the same as the koa ctx object but also includes:

ctx.parameters.path

Object where each property is the name of a path parameter applicable to the operation and it's provided value.

ctx.parameters.query

Object where each property is the name of a query parameter applicable to the operation and it's provided value.

parameters declared w/ application/json content will be deserialized

ctx.security

Object where each property is the name of a security definition applicable to the operation and it's provided value.

for oauth2, value will be the bearer token string

for http bearer, value will be the bearer token string

for http basic, value will be a {userId, password} object

Examples

Basic usage

const getRequestListener = require('listener-from-oas3')
const http = require('http')

async function listen(port) {
  const requestListener = await getRequestListener(
    `${__dirname}/openapi.yaml`,
    // resolve handlers from `${__dirname}/${operation-path}/${operation-method}`
    __dirname
  )

  http
    .createServer(requestListener)
    .listen(port)
}

Support

open an issue

Releases

releases are versioned according to semver 2.0.0 and tagged; see CHANGELOG.md for release notes

Contributing

see CONTRIBUTING.md