@midwayjs/swagger 3.9.9 → 3.10.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.
@@ -1,5 +1,5 @@
1
1
  import { ContentObject, ExamplesObject, ReferenceObject, RequestBodyObject, SchemaObject, SwaggerEnumType } from '../interfaces';
2
- declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
2
+ type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
3
3
  export declare enum BodyContentType {
4
4
  FormUrlEncoded = "application/x-www-form-urlencoded",
5
5
  JSON = "application/json",
@@ -18,7 +18,7 @@ interface ApiBodySchemaHost extends RequestBodyOptions {
18
18
  schema: SchemaObject | ReferenceObject;
19
19
  examples?: ExamplesObject;
20
20
  }
21
- export declare type ApiBodyOptions = ApiBodyMetadata | ApiBodySchemaHost;
21
+ export type ApiBodyOptions = ApiBodyMetadata | ApiBodySchemaHost;
22
22
  export declare function ApiBody(options: ApiBodyOptions): MethodDecorator;
23
23
  export {};
24
24
  //# sourceMappingURL=api-body.decorator.d.ts.map
@@ -1,4 +1,4 @@
1
1
  import { OperationObject } from '../interfaces';
2
- export declare type ApiOperationOptions = Partial<OperationObject>;
2
+ export type ApiOperationOptions = Partial<OperationObject>;
3
3
  export declare function ApiOperation(options: ApiOperationOptions): MethodDecorator;
4
4
  //# sourceMappingURL=api-operation.decorator.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Type, ParameterObject, SchemaObject, SwaggerEnumType } from '../interfaces';
2
- declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
2
+ type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
3
3
  interface ApiParamMetadata extends ParameterOptions {
4
4
  type?: Type | string;
5
5
  format?: string;
@@ -9,7 +9,7 @@ interface ApiParamMetadata extends ParameterOptions {
9
9
  interface ApiParamSchemaHost extends ParameterOptions {
10
10
  schema: SchemaObject;
11
11
  }
12
- export declare type ApiParamOptions = ApiParamMetadata | ApiParamSchemaHost;
12
+ export type ApiParamOptions = ApiParamMetadata | ApiParamSchemaHost;
13
13
  export declare function ApiParam(options: ApiParamOptions): MethodDecorator;
14
14
  export {};
15
15
  //# sourceMappingURL=api-param.decorator.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { Type, ParameterObject, ReferenceObject, SchemaObject, SwaggerEnumType } from '../interfaces';
2
- declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema' | 'name'>;
2
+ type ParameterOptions = Omit<ParameterObject, 'in' | 'schema' | 'name'>;
3
3
  interface ApiQueryMetadata extends ParameterOptions {
4
4
  name?: string;
5
5
  type?: Type | string;
@@ -11,7 +11,7 @@ interface ApiQuerySchemaHost extends ParameterOptions {
11
11
  name?: string;
12
12
  schema: SchemaObject | ReferenceObject;
13
13
  }
14
- export declare type ApiQueryOptions = ApiQueryMetadata | ApiQuerySchemaHost;
14
+ export type ApiQueryOptions = ApiQueryMetadata | ApiQuerySchemaHost;
15
15
  export declare function ApiQuery(options: ApiQueryOptions): MethodDecorator;
16
16
  export {};
17
17
  //# sourceMappingURL=api-query.decorator.d.ts.map
@@ -10,7 +10,7 @@ export interface ApiResponseSchemaHost extends Omit<ResponseObject, 'description
10
10
  status?: number;
11
11
  description?: string;
12
12
  }
13
- export declare type ApiResponseOptions = ApiResponseMetadata | ApiResponseSchemaHost;
13
+ export type ApiResponseOptions = ApiResponseMetadata | ApiResponseSchemaHost;
14
14
  export declare function ApiResponse(options: ApiResponseOptions): any;
15
15
  export declare const ApiOkResponse: (options?: ApiResponseOptions) => any;
16
16
  export declare const ApiCreatedResponse: (options?: ApiResponseOptions) => any;
@@ -50,7 +50,7 @@ export interface ComponentsObject {
50
50
  links?: Record<string, LinkObject | ReferenceObject>;
51
51
  callbacks?: Record<string, CallbackObject | ReferenceObject>;
52
52
  }
53
- export declare type PathsObject = Record<string, PathItemObject>;
53
+ export type PathsObject = Record<string, PathItemObject>;
54
54
  export interface PathItemObject {
55
55
  $ref?: string;
56
56
  summary?: string;
@@ -84,8 +84,8 @@ export interface ExternalDocumentationObject {
84
84
  description?: string;
85
85
  url: string;
86
86
  }
87
- export declare type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
88
- export declare type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
87
+ export type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
88
+ export type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
89
89
  export interface BaseParameterObject {
90
90
  description?: string;
91
91
  required?: boolean;
@@ -108,14 +108,14 @@ export interface RequestBodyObject {
108
108
  content: ContentObject;
109
109
  required?: boolean;
110
110
  }
111
- export declare type ContentObject = Record<string, MediaTypeObject>;
111
+ export type ContentObject = Record<string, MediaTypeObject>;
112
112
  export interface MediaTypeObject {
113
113
  schema?: SchemaObject | ReferenceObject;
114
114
  examples?: ExamplesObject;
115
115
  example?: any;
116
116
  encoding?: EncodingObject;
117
117
  }
118
- export declare type EncodingObject = Record<string, EncodingPropertyObject>;
118
+ export type EncodingObject = Record<string, EncodingPropertyObject>;
119
119
  export interface EncodingPropertyObject {
120
120
  contentType?: string;
121
121
  headers?: Record<string, HeaderObject | ReferenceObject>;
@@ -132,16 +132,16 @@ export interface ResponseObject {
132
132
  content?: ContentObject;
133
133
  links?: LinksObject;
134
134
  }
135
- export declare type CallbacksObject = Record<string, CallbackObject | ReferenceObject>;
136
- export declare type CallbackObject = Record<string, PathItemObject>;
137
- export declare type HeadersObject = Record<string, HeaderObject | ReferenceObject>;
135
+ export type CallbacksObject = Record<string, CallbackObject | ReferenceObject>;
136
+ export type CallbackObject = Record<string, PathItemObject>;
137
+ export type HeadersObject = Record<string, HeaderObject | ReferenceObject>;
138
138
  export interface ExampleObject {
139
139
  summary?: string;
140
140
  description?: string;
141
141
  value?: any;
142
142
  externalValue?: string;
143
143
  }
144
- export declare type LinksObject = Record<string, LinkObject | ReferenceObject>;
144
+ export type LinksObject = Record<string, LinkObject | ReferenceObject>;
145
145
  export interface LinkObject {
146
146
  operationRef?: string;
147
147
  operationId?: string;
@@ -150,14 +150,14 @@ export interface LinkObject {
150
150
  description?: string;
151
151
  server?: ServerObject;
152
152
  }
153
- export declare type LinkParametersObject = Record<string, any>;
154
- export declare type HeaderObject = BaseParameterObject;
153
+ export type LinkParametersObject = Record<string, any>;
154
+ export type HeaderObject = BaseParameterObject;
155
155
  export interface TagObject {
156
156
  name: string;
157
157
  description?: string;
158
158
  externalDocs?: ExternalDocumentationObject;
159
159
  }
160
- export declare type ExamplesObject = Record<string, ExampleObject | ReferenceObject>;
160
+ export type ExamplesObject = Record<string, ExampleObject | ReferenceObject>;
161
161
  export interface ReferenceObject {
162
162
  $ref: string | (() => string);
163
163
  }
@@ -171,7 +171,7 @@ export interface SchemaObject {
171
171
  example?: any;
172
172
  examples?: any[] | Record<string, any>;
173
173
  deprecated?: boolean;
174
- type?: string;
174
+ type?: string | (new (...args: any[]) => any) | (() => new (...args: any[]) => any);
175
175
  allOf?: (SchemaObject | ReferenceObject)[];
176
176
  oneOf?: (SchemaObject | ReferenceObject)[];
177
177
  anyOf?: (SchemaObject | ReferenceObject)[];
@@ -200,7 +200,7 @@ export interface SchemaObject {
200
200
  required?: string[];
201
201
  enum?: any[];
202
202
  }
203
- export declare type SchemasObject = Record<string, SchemaObject>;
203
+ export type SchemasObject = Record<string, SchemaObject>;
204
204
  export interface DiscriminatorObject {
205
205
  propertyName: string;
206
206
  mapping?: Record<string, string>;
@@ -212,7 +212,7 @@ export interface XmlObject {
212
212
  attribute?: boolean;
213
213
  wrapped?: boolean;
214
214
  }
215
- export declare type SecuritySchemeType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
215
+ export type SecuritySchemeType = 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
216
216
  export interface SecuritySchemeObject {
217
217
  type: SecuritySchemeType;
218
218
  description?: string;
@@ -235,12 +235,12 @@ export interface OAuthFlowObject {
235
235
  refreshUrl?: string;
236
236
  scopes: ScopesObject;
237
237
  }
238
- export declare type ScopesObject = Record<string, any>;
239
- export declare type SecurityRequirementObject = Record<string, string[]>;
238
+ export type ScopesObject = Record<string, any>;
239
+ export type SecurityRequirementObject = Record<string, string[]>;
240
240
  /**
241
241
  * 非 open api spec
242
242
  */
243
- export declare type SwaggerEnumType = string[] | number[] | (string | number)[] | Record<number, string>;
243
+ export type SwaggerEnumType = string[] | number[] | (string | number)[] | Record<number, string>;
244
244
  export interface Type<T = any> extends Function {
245
245
  new (...args: any[]): T;
246
246
  }
@@ -251,7 +251,7 @@ export interface SchemaObjectMetadata extends Omit<SchemaObject, 'type' | 'requi
251
251
  name?: string;
252
252
  enumName?: string;
253
253
  }
254
- export declare type AuthType = 'basic' | 'bearer' | 'cookie' | 'oauth2' | 'apikey' | 'custom';
254
+ export type AuthType = 'basic' | 'bearer' | 'cookie' | 'oauth2' | 'apikey' | 'custom';
255
255
  /**
256
256
  * 继承自 https://swagger.io/specification/#security-scheme-object
257
257
  */
@@ -23,6 +23,7 @@ export declare class SwaggerExplorer {
23
23
  * @param clzz
24
24
  */
25
25
  private parseExtraModel;
26
+ protected parseSubPropertyType(metadata: any): any;
26
27
  /**
27
28
  * 解析类型的 ApiProperty
28
29
  * @param clzz
@@ -499,6 +499,104 @@ let SwaggerExplorer = class SwaggerExplorer {
499
499
  }
500
500
  }
501
501
  }
502
+ parseSubPropertyType(metadata) {
503
+ var _a, _b, _c;
504
+ let typeMeta;
505
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.enum) {
506
+ typeMeta = {
507
+ type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
508
+ enum: metadata === null || metadata === void 0 ? void 0 : metadata.enum,
509
+ default: metadata === null || metadata === void 0 ? void 0 : metadata.default,
510
+ };
511
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.description) {
512
+ typeMeta.description = metadata === null || metadata === void 0 ? void 0 : metadata.description;
513
+ }
514
+ return typeMeta;
515
+ }
516
+ if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _a === void 0 ? void 0 : _a.enum) {
517
+ typeMeta = {
518
+ type: metadata === null || metadata === void 0 ? void 0 : metadata.type,
519
+ items: metadata === null || metadata === void 0 ? void 0 : metadata.items,
520
+ default: metadata === null || metadata === void 0 ? void 0 : metadata.default,
521
+ };
522
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.description) {
523
+ typeMeta.description = metadata === null || metadata === void 0 ? void 0 : metadata.description;
524
+ }
525
+ return typeMeta;
526
+ }
527
+ let isArray = false;
528
+ let currentType = parseTypeSchema(metadata === null || metadata === void 0 ? void 0 : metadata.type);
529
+ metadata === null || metadata === void 0 ? true : delete metadata.type;
530
+ if (currentType === 'array') {
531
+ isArray = true;
532
+ currentType = parseTypeSchema((_b = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _b === void 0 ? void 0 : _b.type);
533
+ metadata === null || metadata === void 0 ? true : delete metadata.items.type;
534
+ }
535
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.oneOf) {
536
+ typeMeta = {
537
+ oneOf: [],
538
+ };
539
+ metadata === null || metadata === void 0 ? void 0 : metadata.oneOf.forEach((item) => {
540
+ typeMeta.push(this.parseSubPropertyType(item));
541
+ });
542
+ metadata === null || metadata === void 0 ? true : delete metadata.oneOf;
543
+ }
544
+ if (core_1.Types.isClass(currentType)) {
545
+ this.parseClzz(currentType);
546
+ if (isArray) {
547
+ typeMeta = {
548
+ type: 'array',
549
+ items: {
550
+ $ref: '#/components/schemas/' + (currentType === null || currentType === void 0 ? void 0 : currentType.name),
551
+ },
552
+ };
553
+ }
554
+ else {
555
+ typeMeta = {
556
+ $ref: '#/components/schemas/' + (currentType === null || currentType === void 0 ? void 0 : currentType.name),
557
+ };
558
+ }
559
+ delete metadata.items;
560
+ }
561
+ else {
562
+ if (isArray) {
563
+ // 没有配置类型则认为自己配置了 items 内容
564
+ if (!currentType) {
565
+ if ((_c = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _c === void 0 ? void 0 : _c['$ref']) {
566
+ metadata.items['$ref'] = parseTypeSchema(metadata.items['$ref']);
567
+ }
568
+ typeMeta = {
569
+ type: 'array',
570
+ items: metadata === null || metadata === void 0 ? void 0 : metadata.items,
571
+ };
572
+ }
573
+ else {
574
+ typeMeta = {
575
+ type: 'array',
576
+ items: {
577
+ type: convertSchemaType((currentType === null || currentType === void 0 ? void 0 : currentType.name) || currentType),
578
+ },
579
+ };
580
+ }
581
+ delete metadata.items;
582
+ }
583
+ else {
584
+ typeMeta = {
585
+ type: currentType,
586
+ format: metadata === null || metadata === void 0 ? void 0 : metadata.format,
587
+ };
588
+ // Date 类型支持
589
+ if (typeMeta.type === 'Date') {
590
+ typeMeta.type = 'string';
591
+ if (!typeMeta.format) {
592
+ typeMeta.format = 'date';
593
+ }
594
+ }
595
+ delete metadata.format;
596
+ }
597
+ }
598
+ return Object.assign(typeMeta, metadata);
599
+ }
502
600
  /**
503
601
  * 解析类型的 ApiProperty
504
602
  * @param clzz
@@ -553,9 +651,19 @@ let SwaggerExplorer = class SwaggerExplorer {
553
651
  metadata === null || metadata === void 0 ? true : delete metadata.type;
554
652
  if (currentType === 'array') {
555
653
  isArray = true;
556
- currentType = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _b === void 0 ? void 0 : _b.type;
654
+ currentType = parseTypeSchema((_b = metadata === null || metadata === void 0 ? void 0 : metadata.items) === null || _b === void 0 ? void 0 : _b.type);
557
655
  metadata === null || metadata === void 0 ? true : delete metadata.items.type;
558
656
  }
657
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.oneOf) {
658
+ tt.properties[key] = {
659
+ oneOf: [],
660
+ };
661
+ metadata === null || metadata === void 0 ? void 0 : metadata.oneOf.forEach((meta) => {
662
+ tt.properties[key].oneOf.push(this.parseSubPropertyType(meta));
663
+ });
664
+ metadata === null || metadata === void 0 ? true : delete metadata.oneOf;
665
+ return;
666
+ }
559
667
  if (core_1.Types.isClass(currentType)) {
560
668
  this.parseClzz(currentType);
561
669
  if (isArray) {
@@ -756,9 +864,18 @@ function getNotEmptyValue(...args) {
756
864
  }
757
865
  }
758
866
  function parseTypeSchema(ref) {
759
- if (typeof ref === 'function' && !core_1.Types.isClass(ref)) {
760
- ref = ref();
867
+ switch (ref) {
868
+ case String:
869
+ return 'string';
870
+ case Number:
871
+ return 'number';
872
+ case Boolean:
873
+ return 'boolean';
874
+ default:
875
+ if (typeof ref === 'function' && !core_1.Types.isClass(ref)) {
876
+ ref = ref();
877
+ }
878
+ return ref;
761
879
  }
762
- return ref;
763
880
  }
764
881
  //# sourceMappingURL=swaggerExplorer.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/swagger",
3
- "version": "3.9.9",
3
+ "version": "3.10.1",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "files": [
@@ -9,10 +9,10 @@
9
9
  "index.d.ts"
10
10
  ],
11
11
  "devDependencies": {
12
- "@midwayjs/core": "^3.9.0",
13
- "@midwayjs/koa": "^3.9.9",
14
- "@midwayjs/mock": "^3.9.0",
15
- "@midwayjs/validate": "^3.9.9",
12
+ "@midwayjs/core": "^3.10.1",
13
+ "@midwayjs/koa": "^3.10.1",
14
+ "@midwayjs/mock": "^3.10.1",
15
+ "@midwayjs/validate": "^3.10.1",
16
16
  "swagger-ui-dist": "4.15.5"
17
17
  },
18
18
  "author": "Kurten Chan <chinkurten@gmail.com>",
@@ -27,5 +27,5 @@
27
27
  "type": "git",
28
28
  "url": "https://github.com/midwayjs/midway.git"
29
29
  },
30
- "gitHead": "95bb5b3f23b41f685372c45d1c3bb12a3e31b4e0"
30
+ "gitHead": "6bc9f7a97e4188399d2406f5a38bad5aeb983e07"
31
31
  }