Giter Site home page Giter Site logo

koa-oas3's Introduction

koa-oas3

Request and Response validator for OpenAPI Specification 3.

Installation

npm

npm install --save koa-oas3

yarn

yarn add koa-oas3

API

By default, this library will use koa-bodyparser to parse request body. See config of requestBodyHandler.

import * as bodyParser from 'koa-bodyparser';
import { oas } from 'koa-oas3';

const app = new Koa();
app.use(bodyParser());
app.use(oas({
  file: `${__dirname}/../openapi.yaml`,
  endpoint: '/openapi.json',
  uiEndpoint: '/'
});

app.listen(8080);

oas(option)

options:

  • file - The absolute path to your Openapi file
  • spec - javascript object defining the api, either this or file must be given.
  • enableUi(default: true) - Whether to enable serving Openapi JSON and UI
  • endpoint(default: /openapi.json) - The endpoint for serving Openapi JSON
  • uiEndpoint:(default: /openapi.html) - The endpoint for serving Openapi UI
  • validateResponse:(default: false) - Validate response against Openapi schemas
  • validatePaths:(default ['/']) - Only endpoints starting with the values specified here will be validated
  • swaggerUiBundleBasePath: (default use swagger-ui-dist from unpkg) - swaggerUiAssetPath needed for loading the swagger-ui
  • errorHandler: (error: Error, ctx: Context) => void,: Optional - custom error hanlder.
  • requestBodyHandler: { [key: string]: koa.Middleware }: Optional - custom body handler. Defaults:
{
  'application/json': bodyParser({
    extendTypes: {
      json: ['application/json']
    },
    enableTypes: ['json']
  }),
  'text/*': bodyParser({
    extendTypes: {
      text: ['text/*']
    },
    enableTypes: ['text']
  }),
  'application/x-www-form-urlencoded': bodyParser({
    extendTypes: {
      form: ['application/x-www-form-urlencoded']
    },
    enableTypes: ['form']
  })
}

koa-oas3's People

Contributors

acheronfail avatar atlastong avatar github-actions[bot] avatar jfmeachum avatar lukiano avatar ngot avatar sakari avatar supertong avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.