Skip to content

oaijs/koa-oai-router-middleware

Repository files navigation

Koa-OAI-Router-Middleware

License Node Version NPM Version Build Status Test Coverage Downloads Dependency Status

Middleware loader plugin koa-oai-router

Installation

npm i koa-oai-router-middleware --save

Info

field type info
plugin class string MiddlewarePlugin
plugin name string middleware
evoked fields string|[string] x-oai-middleware, x-middleware, x-oai-controller, x-controller
evoked fileds value [{file,handler}] file is relative file path of middleware , handler is name of middleware exported
options string|object if options is string, effect same as object contains dir, middlewareDir and middleware.

Usage

In this example, we will load middlewares from ./controllers directory and recognize the value of x-oai-middleware then bind them to a api.

const Koa = require('koa');
const Router = require('koa-oai-router');
const MiddlewarePlugin = require('koa-oai-router-middleware');

const app = new Koa();
const router = new Router({
  apiDoc: './api',
  options: {
    middleware: './controllers',
    // OR
    MiddlewarePlugin: './controllers',
  },
});

router.mount(MiddlewarePlugin);

app.use(bodyParser());
app.use(router.routes());
# ./api/paths/pets.yaml

/pets:
  get:
    description: "Returns all pets from the system that the user has access to"
    x-oai-middleware:
      - file: pets
        handler: get
    parameters:
      - name: "tags"
        in: "query"
        description: "tags to filter by"
        required: false
        type: "array"
        items:
          type: "string"
        collectionFormat: "csv"
      - name: "limit"
        in: "query"
        description: "maximum number of results to return"
        required: false
        type: "integer"
        format: "int32"
    responses:
      "200":
        description: "pet response"
        schema:
          type: "array"
          items:
            $ref: "#/definitions/Pet"

About

Middleware loader plugin koa-oai-router

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published