1.1.2 • Published 6 years ago

koa-oai-router-middleware v1.1.2

Weekly downloads
179
License
MIT
Repository
-
Last release
6 years ago

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

fieldtypeinfo
plugin classstringMiddlewarePlugin
plugin namestringmiddleware
evoked fieldsstring|stringx-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
optionsstring|objectif 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"