1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| import { Provide } from '@midwayjs/decorator';
| import { IWebMiddleware, IMidwayWebNext } from '@midwayjs/web';
| import { Context } from 'egg';
| import * as _ from 'lodash';
|
| /**
| * swagger
| */
| @Provide()
| export class BaseSwaggerMiddleware implements IWebMiddleware {
| resolve() {
| return async (ctx: Context, next: IMidwayWebNext) => {
| const { url } = ctx;
| await next();
| if (_.startsWith(url, '/swagger-ui/json')) {
| ctx.body.components.securitySchemes = {
| Authorization: {
| type: 'apiKey',
| name: 'Authorization',
| in: 'header',
| },
| };
| ctx.body.security = [{ Authorization: [] }];
| }
| };
| }
| }
|
|