https://github.com/rickyli79/egg-openapi-router
init `router` and connect `controller` by Openapi-doc. validate the request and response by Openapi-doc
https://github.com/rickyli79/egg-openapi-router
egg egg-plugin eggplugin openapi route schema valid
Last synced: 2 months ago
JSON representation
init `router` and connect `controller` by Openapi-doc. validate the request and response by Openapi-doc
- Host: GitHub
- URL: https://github.com/rickyli79/egg-openapi-router
- Owner: RickyLi79
- License: mit
- Created: 2021-02-20T13:19:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-26T17:32:37.000Z (over 4 years ago)
- Last Synced: 2025-03-02T23:05:15.372Z (3 months ago)
- Topics: egg, egg-plugin, eggplugin, openapi, route, schema, valid
- Language: TypeScript
- Homepage:
- Size: 649 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-openapi-router
[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[npm-image]: https://img.shields.io/npm/v/egg-openapi-router.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-openapi-router
[download-image]: https://img.shields.io/npm/dm/egg-openapi-router.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-openapi-router[@rickyli79/koa-openapi-router](https://github.com/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
```bash
$ npm i --save egg-openapi-router
```## Usage & configuration
#### Enable plugin in `config/plugin.js`
``` js
exports.openapiRouter = {
enable: true,
package: 'egg-openapi-router'
}
```#### Edit your own configurations in `config/config.{env}.js`
- Single config
```js
// 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
```js
// 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:
```yaml
# openapi-doc/my.oas3.json
openapi: "3.0.0"
paths:
/hello:
get:
responses:
200:
description: ok
```#### edit `config/config.{env}.js`:
```js
// config/config.{env}.js
exports.openapiRouter = {
config: {
controllerDir: '',
docsDir: path.join(appInfo.baseDir, 'openapi-doc'),
routerPrefix: '',
},
};
```#### controller:
```js
// 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](https://github.com/RickyLi79/openapi-mock-server) is an example for [@rickyli79/json-schema-mock](https://npmjs.org/package/@rickyli79/json-schema-mock) and [egg-openapi-router](https://npmjs.org/package/egg-openapi-router)#### Test Report
[Allure Report](https://rickyli79.github.io/testing-reports/egg-openapi-router/allure-report/)## License
[MIT](LICENSE)