@midwayjs/swagger 3.20.4 → 3.20.6-beta.1

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/
@@ -854,52 +854,40 @@ let SwaggerExplorer = class SwaggerExplorer {
854
854
  if (!opts) {
855
855
  return;
856
856
  }
857
- const authType = opts.authType;
858
- delete opts.authType;
859
- // TODO 加 security
857
+ const { authType, name = '', addSecurityRequirements = false, ...otherOptions } = opts;
858
+ if (!authType) {
859
+ return;
860
+ }
860
861
  switch (authType) {
861
- case 'basic':
862
- {
863
- const name = opts.name;
864
- delete opts.name;
865
- this.documentBuilder.addBasicAuth(opts, name);
866
- }
862
+ case 'basic': {
863
+ this.documentBuilder.addBasicAuth(otherOptions, name);
867
864
  break;
868
- case 'bearer':
869
- {
870
- const name = opts.name;
871
- delete opts.name;
872
- this.documentBuilder.addBearerAuth(opts, name);
873
- }
865
+ }
866
+ case 'bearer': {
867
+ this.documentBuilder.addBearerAuth(otherOptions, name);
874
868
  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
- }
869
+ }
870
+ case 'cookie': {
871
+ const { cookieName, securityName, ...options } = otherOptions;
872
+ this.documentBuilder.addCookieAuth(cookieName, options, securityName);
883
873
  break;
884
- case 'oauth2':
885
- {
886
- const name = opts.name;
887
- delete opts.name;
888
- this.documentBuilder.addOAuth2(opts, name);
889
- }
874
+ }
875
+ case 'oauth2': {
876
+ this.documentBuilder.addOAuth2(otherOptions, name);
890
877
  break;
891
- case 'apikey':
892
- {
893
- const name = opts.name;
894
- delete opts.name;
895
- this.documentBuilder.addApiKey(opts, name);
896
- }
878
+ }
879
+ case 'apikey': {
880
+ this.documentBuilder.addApiKey(otherOptions, name);
897
881
  break;
898
- case 'custom':
899
- {
900
- this.documentBuilder.addSecurity(opts === null || opts === void 0 ? void 0 : opts.name, opts);
901
- }
882
+ }
883
+ case 'custom': {
884
+ this.documentBuilder.addSecurity(name, otherOptions);
902
885
  break;
886
+ }
887
+ }
888
+ if (addSecurityRequirements) {
889
+ // 添加安全要求
890
+ this.documentBuilder.addSecurityRequirements(name);
903
891
  }
904
892
  }
905
893
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "3.20.4",
3
+ "version": "3.20.6-beta.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
@@ -11,10 +11,11 @@
11
11
  ],
12
12
  "devDependencies": {
13
13
  "@midwayjs/core": "^3.20.4",
14
- "@midwayjs/koa": "^3.20.4",
14
+ "@midwayjs/koa": "^3.20.5",
15
15
  "@midwayjs/mock": "^3.20.4",
16
- "@midwayjs/validate": "^3.20.4",
17
- "swagger-ui-dist": "5.18.3"
16
+ "@midwayjs/validate": "^3.20.5",
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": "c3fb65a7ada8829635f3c6af5ef83c65c3a43d79"
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.