1.0.11 • Published 3 years ago

egg-openapi-router v1.0.11

Weekly downloads
510
License
MIT
Repository
github
Last release
3 years ago

egg-openapi-router

NPM version npm download NPM

@rickyli79/koa-openapi-router plugin for Egg.js.

NOTE: This plugin just for Egg.js, more documentation please visit https://github.com/RickyLi79/koa-openapi-router.

Install

$ npm i --save egg-openapi-router

Usage & configuration

Enable plugin in config/plugin.js

exports.openapiRouter = {
  enable: true,
  package: 'egg-openapi-router'
}

Edit your own configurations in config/config.{env}.js

  • Single config
    // config/config.{env}.js
    exports.openapiRouter = {
      config: {
        controllerDir: 'my/api/dir', // default: ''
        docsDir: path.join(appInfo.baseDir, 'my-openapi-doc'), // default: path.join(appInfo.baseDir, 'openapi-doc')
        routerPrefix: '/myApi', // default : ''
      },
    };
  • Muti Configs
    // config/config.{env}.js
    exports.openapiRouter = {
      configs: {
        'my/api/module/1': {
          controllerDir: 'module-1',
          docsDir: path.join(appInfo.baseDir, 'openapi-doc-module-1'),
        },
        'my/api/module/2': {
          controllerDir: 'module-2',
          docsDir: path.join(appInfo.baseDir, 'openapi-doc-module-2'),
        },
      },
    };

Examples

openapi-docs:

# openapi-doc/my.oas3.json
openapi: "3.0.0"
paths:
  /hello:
    get:
      responses:
        200:
          description: ok

edit config/config.{env}.js:

// config/config.{env}.js
exports.openapiRouter = {
  config: {
    controllerDir: '', 
    docsDir: path.join(appInfo.baseDir, 'openapi-doc'),
    routerPrefix: '',
  },
};

controller:

// app/controller/default.js
const Controller = require('egg').Controller;
class DefaultController extends Controller {
  async 'GET /hello'() {
    const { ctx } = this;
    ctx.status = 200;
    ctx.body = 'nihao';
  }
}
module.exports = DefaultController;

More documentation please visit https://github.com/RickyLi79/koa-openapi-router.

Example

Here is an example for @rickyli79/json-schema-mock and egg-openapi-router

Test Report

Allure Report

License

MIT

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago