@midwayjs/swagger 3.20.5 → 3.20.6-beta.2

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.
@@ -280,6 +280,10 @@ export interface AuthOptions extends Omit<SecuritySchemeObject, 'type'> {
280
280
  * authType = cookie 时可以修改,cookie 的名称
281
281
  */
282
282
  cookieName?: string;
283
+ /**
284
+ * 添加全局默认要求
285
+ */
286
+ addSecurityRequirements?: boolean;
283
287
  }
284
288
  /**
285
289
  * see https://swagger.io/specification/
@@ -225,7 +225,11 @@ let SwaggerExplorer = class SwaggerExplorer {
225
225
  return item.key === constants_1.DECORATORS.API_EXCLUDE_SECURITY;
226
226
  });
227
227
  // 如果存在安全信息,则将其添加到路径中
228
- if (security.length > 0 && !excludeSecurity) {
228
+ if (excludeSecurity) {
229
+ // 显式设置为空数组,覆盖全局 security
230
+ paths[url][webRouter.requestMethod].security = [];
231
+ }
232
+ else if (security.length > 0) {
229
233
  if (!paths[url][webRouter.requestMethod].security) {
230
234
  paths[url][webRouter.requestMethod].security = [];
231
235
  }
@@ -854,52 +858,40 @@ let SwaggerExplorer = class SwaggerExplorer {
854
858
  if (!opts) {
855
859
  return;
856
860
  }
857
- const authType = opts.authType;
858
- delete opts.authType;
859
- // TODO 加 security
861
+ const { authType, name = '', addSecurityRequirements = false, ...otherOptions } = opts;
862
+ if (!authType) {
863
+ return;
864
+ }
860
865
  switch (authType) {
861
- case 'basic':
862
- {
863
- const name = opts.name;
864
- delete opts.name;
865
- this.documentBuilder.addBasicAuth(opts, name);
866
- }
866
+ case 'basic': {
867
+ this.documentBuilder.addBasicAuth(otherOptions, name);
867
868
  break;
868
- case 'bearer':
869
- {
870
- const name = opts.name;
871
- delete opts.name;
872
- this.documentBuilder.addBearerAuth(opts, name);
873
- }
869
+ }
870
+ case 'bearer': {
871
+ this.documentBuilder.addBearerAuth(otherOptions, name);
874
872
  break;
875
- case 'cookie':
876
- {
877
- const cname = opts.cookieName;
878
- const secName = opts.securityName;
879
- delete opts.cookieName;
880
- delete opts.securityName;
881
- this.documentBuilder.addCookieAuth(cname, opts, secName);
882
- }
873
+ }
874
+ case 'cookie': {
875
+ const { cookieName, securityName, ...options } = otherOptions;
876
+ this.documentBuilder.addCookieAuth(cookieName, options, securityName);
883
877
  break;
884
- case 'oauth2':
885
- {
886
- const name = opts.name;
887
- delete opts.name;
888
- this.documentBuilder.addOAuth2(opts, name);
889
- }
878
+ }
879
+ case 'oauth2': {
880
+ this.documentBuilder.addOAuth2(otherOptions, name);
890
881
  break;
891
- case 'apikey':
892
- {
893
- const name = opts.name;
894
- delete opts.name;
895
- this.documentBuilder.addApiKey(opts, name);
896
- }
882
+ }
883
+ case 'apikey': {
884
+ this.documentBuilder.addApiKey(otherOptions, name);
897
885
  break;
898
- case 'custom':
899
- {
900
- this.documentBuilder.addSecurity(opts === null || opts === void 0 ? void 0 : opts.name, opts);
901
- }
886
+ }
887
+ case 'custom': {
888
+ this.documentBuilder.addSecurity(name, otherOptions);
902
889
  break;
890
+ }
891
+ }
892
+ if (addSecurityRequirements) {
893
+ // 添加安全要求
894
+ this.documentBuilder.addSecurityRequirements(name);
903
895
  }
904
896
  }
905
897
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "3.20.5",
3
+ "version": "3.20.6-beta.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
@@ -14,7 +14,8 @@
14
14
  "@midwayjs/koa": "^3.20.5",
15
15
  "@midwayjs/mock": "^3.20.4",
16
16
  "@midwayjs/validate": "^3.20.5",
17
- "swagger-ui-dist": "5.18.3"
17
+ "swagger-ui-dist": "5.18.3",
18
+ "@apidevtools/swagger-parser": "11.0.1"
18
19
  },
19
20
  "author": "Kurten Chan <chinkurten@gmail.com>",
20
21
  "license": "MIT",
@@ -26,6 +27,5 @@
26
27
  "repository": {
27
28
  "type": "git",
28
29
  "url": "https://github.com/midwayjs/midway.git"
29
- },
30
- "gitHead": "7ce57281bd3ef5d18dc50b47ff9bffb8a27c071e"
30
+ }
31
31
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.