@midwayjs/swagger 3.20.6-beta.3 → 3.20.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013 - Now midwayjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,2 +1,2 @@
1
- export declare function ApiBasicAuth(name?: string): ClassDecorator;
1
+ export declare function ApiBasicAuth(name?: string): ClassDecorator & MethodDecorator;
2
2
  //# sourceMappingURL=api-basic.decorator.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare function ApiBearerAuth(name?: string): ClassDecorator;
1
+ export declare function ApiBearerAuth(name?: string): ClassDecorator & MethodDecorator;
2
2
  //# sourceMappingURL=api-bearer.decorator.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare function ApiCookieAuth(name?: string): ClassDecorator;
1
+ export declare function ApiCookieAuth(name?: string): ClassDecorator & MethodDecorator;
2
2
  //# sourceMappingURL=api-cookie.decorator.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare function ApiOAuth2(scopes: string[], name?: string): ClassDecorator;
1
+ export declare function ApiOAuth2(scopes: string[], name?: string): ClassDecorator & MethodDecorator;
2
2
  //# sourceMappingURL=api-oauth2.decorator.d.ts.map
@@ -1,4 +1,4 @@
1
1
  import { SecurityRequirementObject } from '../interfaces';
2
- export declare function ApiSecurity(name: string | SecurityRequirementObject, requirements?: string[]): ClassDecorator;
2
+ export declare function ApiSecurity(name: string | SecurityRequirementObject, requirements?: string[]): ClassDecorator & MethodDecorator;
3
3
  export declare function ApiExcludeSecurity(): ClassDecorator & MethodDecorator;
4
4
  //# sourceMappingURL=api-security.decorator.d.ts.map
@@ -162,8 +162,8 @@ let SwaggerExplorer = class SwaggerExplorer {
162
162
  if (headers.length > 0) {
163
163
  headers = headers.map(item => item.metadata);
164
164
  }
165
- // 过滤出安全信息
166
- const security = metaForClass.filter(item => item.key === constants_1.DECORATORS.API_SECURITY);
165
+ // 过滤出安全信息(方法优先)
166
+ const classSecurity = metaForClass.filter(item => item.key === constants_1.DECORATORS.API_SECURITY);
167
167
  // 初始化路径对象
168
168
  const paths = {};
169
169
  // 如果存在路由信息,则遍历生成路径
@@ -174,6 +174,7 @@ let SwaggerExplorer = class SwaggerExplorer {
174
174
  url = replaceUrl(url, parseParamsInPath(url));
175
175
  // 方法元数据
176
176
  const metaForMethods = (0, core_1.getPropertyDataFromClass)(constants_1.DECORATORS_METHOD_METADATA, target, webRouter.method) || [];
177
+ const methodSecurity = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_SECURITY);
177
178
  // 判断是否忽略当前路由
178
179
  const endpoints = metaForMethods.filter(item => item.key === constants_1.DECORATORS.API_EXCLUDE_ENDPOINT &&
179
180
  item.propertyName === webRouter.method);
@@ -221,25 +222,26 @@ let SwaggerExplorer = class SwaggerExplorer {
221
222
  Object.assign(paths[url][webRouter.requestMethod], e.metadata);
222
223
  }
223
224
  }
224
- // 检查类和方法上的 ApiExcludeSecurity
225
- const excludeSecurityClass = metaForClass.find(item => item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY);
226
- const excludeSecurityMethod = metaForMethods.find(item => item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY);
227
- const excludeSecurity = excludeSecurityClass || excludeSecurityMethod;
228
- // 如果存在安全信息,则将其添加到路径中
229
- if (excludeSecurity) {
230
- // 显式设置为空数组,覆盖全局 security
225
+ // 优先级处理:method exclude > method security > class exclude > class security
226
+ const hasMethodExclude = metaForMethods.find(item => item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY);
227
+ const hasMethodSecurity = methodSecurity.length > 0;
228
+ const hasClassExclude = metaForClass.find(item => item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY);
229
+ const hasClassSecurity = classSecurity.length > 0;
230
+ if (hasMethodExclude) {
231
231
  paths[url][webRouter.requestMethod].security = [];
232
232
  }
233
- else if (security.length > 0) {
234
- if (!paths[url][webRouter.requestMethod].security) {
235
- paths[url][webRouter.requestMethod].security = [];
236
- }
237
- for (const s of security) {
238
- if (!s.metadata) {
239
- continue;
240
- }
241
- paths[url][webRouter.requestMethod].security.push(s.metadata);
242
- }
233
+ else if (hasMethodSecurity) {
234
+ paths[url][webRouter.requestMethod].security = methodSecurity
235
+ .map(s => s.metadata)
236
+ .filter(Boolean);
237
+ }
238
+ else if (hasClassExclude) {
239
+ paths[url][webRouter.requestMethod].security = [];
240
+ }
241
+ else if (hasClassSecurity) {
242
+ paths[url][webRouter.requestMethod].security = classSecurity
243
+ .map(s => s.metadata)
244
+ .filter(Boolean);
243
245
  }
244
246
  }
245
247
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "3.20.6-beta.3",
3
+ "version": "3.20.11",
4
4
  "main": "dist/index.js",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
@@ -10,12 +10,12 @@
10
10
  "index.html"
11
11
  ],
12
12
  "devDependencies": {
13
- "@midwayjs/core": "^3.20.4",
14
- "@midwayjs/koa": "^3.20.5",
15
- "@midwayjs/mock": "^3.20.4",
16
- "@midwayjs/validate": "^3.20.5",
17
- "swagger-ui-dist": "5.18.3",
18
- "@apidevtools/swagger-parser": "11.0.1"
13
+ "@apidevtools/swagger-parser": "11.0.1",
14
+ "@midwayjs/core": "^3.20.11",
15
+ "@midwayjs/koa": "^3.20.11",
16
+ "@midwayjs/mock": "^3.20.11",
17
+ "@midwayjs/validate": "^3.20.11",
18
+ "swagger-ui-dist": "5.18.3"
19
19
  },
20
20
  "author": "Kurten Chan <chinkurten@gmail.com>",
21
21
  "license": "MIT",
@@ -27,5 +27,6 @@
27
27
  "repository": {
28
28
  "type": "git",
29
29
  "url": "https://github.com/midwayjs/midway.git"
30
- }
30
+ },
31
+ "gitHead": "741e5e2cd200d44182bf893f348f58fb5c4e5404"
31
32
  }