@midwayjs/swagger 1.0.7 → 3.0.0-beta.9
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/README.md +7 -23
- package/dist/common/enum.utils.d.ts +9 -0
- package/dist/common/enum.utils.js +63 -0
- package/dist/common/httpStatus.d.ts +51 -0
- package/dist/common/httpStatus.js +55 -0
- package/dist/config/config.default.d.ts +2 -8
- package/dist/config/config.default.js +6 -6
- package/dist/configuration.d.ts +4 -2
- package/dist/configuration.js +28 -12
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +18 -0
- package/dist/decorators/api-basic.decorator.d.ts +2 -0
- package/dist/decorators/api-basic.decorator.js +9 -0
- package/dist/decorators/api-bearer.decorator.d.ts +2 -0
- package/dist/decorators/api-bearer.decorator.js +9 -0
- package/dist/decorators/api-body.decorator.d.ts +16 -0
- package/dist/decorators/api-body.decorator.js +27 -0
- package/dist/decorators/api-cookie.decorator.d.ts +2 -0
- package/dist/decorators/api-cookie.decorator.js +9 -0
- package/dist/decorators/api-exclude-controller.decorator.d.ts +2 -0
- package/dist/decorators/api-exclude-controller.decorator.js +12 -0
- package/dist/decorators/api-exclude-endpoint.decorator.d.ts +2 -0
- package/dist/decorators/api-exclude-endpoint.decorator.js +12 -0
- package/dist/decorators/api-extension.decorator.d.ts +2 -0
- package/dist/decorators/api-extension.decorator.js +16 -0
- package/dist/decorators/api-header.decorator.d.ts +7 -0
- package/dist/decorators/api-header.decorator.js +43 -0
- package/dist/decorators/api-oauth2.decorator.d.ts +2 -0
- package/dist/decorators/api-oauth2.decorator.js +9 -0
- package/dist/decorators/api-operation.decorator.d.ts +4 -0
- package/dist/decorators/api-operation.decorator.js +16 -0
- package/dist/decorators/api-param.decorator.d.ts +15 -0
- package/dist/decorators/api-param.decorator.js +30 -0
- package/dist/decorators/api-property.decorator.d.ts +11 -0
- package/dist/decorators/api-property.decorator.js +56 -0
- package/dist/decorators/api-query.decorator.d.ts +17 -0
- package/dist/decorators/api-query.decorator.js +31 -0
- package/dist/decorators/api-response.decorator.d.ts +41 -0
- package/dist/decorators/api-response.decorator.js +149 -0
- package/dist/decorators/api-security.decorator.d.ts +3 -0
- package/dist/decorators/api-security.decorator.js +17 -0
- package/dist/decorators/api-tags.decorator.d.ts +2 -0
- package/dist/decorators/api-tags.decorator.js +10 -0
- package/dist/decorators/helpers.d.ts +7 -0
- package/dist/decorators/helpers.js +41 -0
- package/dist/decorators/index.d.ts +18 -0
- package/dist/decorators/index.js +35 -0
- package/dist/documentBuilder.d.ts +25 -0
- package/dist/documentBuilder.js +192 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +9 -6
- package/dist/interfaces/index.d.ts +268 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/swaggerExplorer.d.ts +30 -0
- package/dist/swaggerExplorer.js +567 -0
- package/dist/swaggerMiddleware.d.ts +9 -0
- package/dist/swaggerMiddleware.js +123 -0
- package/index.d.ts +8 -0
- package/package.json +17 -17
- package/CHANGELOG.md +0 -104
- package/dist/controller/swagger.d.ts +0 -31
- package/dist/controller/swagger.js +0 -94
- package/dist/interface.d.ts +0 -16
- package/dist/interface.js +0 -3
- package/dist/lib/createAPI.d.ts +0 -51
- package/dist/lib/createAPI.js +0 -276
- package/dist/lib/document.d.ts +0 -117
- package/dist/lib/document.js +0 -131
- package/dist/lib/generator.d.ts +0 -30
- package/dist/lib/generator.js +0 -240
- package/dist/service/generator.d.ts +0 -24
- package/dist/service/generator.js +0 -37
package/README.md
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# midwayjs swagger module
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](http://packagequality.com/#?package=midway-core)
|
|
4
|
+
[](https://github.com/midwayjs/midway/pulls)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
npm install @midwayjs/swagger --save
|
|
7
|
-
npm install swagger-ui-dist --save-dev // If you view swagger documentation on in local env
|
|
6
|
+
this is a sub package for midway.
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
```
|
|
8
|
+
Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
|
|
11
9
|
|
|
12
|
-
##
|
|
10
|
+
## License
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- [x] api name
|
|
17
|
-
- [x] api args name
|
|
18
|
-
- [x] api tag(prefix)
|
|
19
|
-
- [x] api args type
|
|
20
|
-
- [x] DTO generate definition schema
|
|
21
|
-
- [x] body(object)
|
|
22
|
-
|
|
23
|
-
**Need add Code**
|
|
24
|
-
|
|
25
|
-
- [x] api description and summary
|
|
26
|
-
- [x] api args required
|
|
27
|
-
- [x] api args example
|
|
28
|
-
- [x] api response code and result format
|
|
12
|
+
[MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SchemaObjectMetadata, SwaggerEnumType } from '../interfaces';
|
|
2
|
+
export declare function getEnumValues(enumType: SwaggerEnumType): string[] | number[];
|
|
3
|
+
export declare function getEnumType(values: (string | number)[]): 'string' | 'number';
|
|
4
|
+
export declare function addEnumArraySchema(paramDefinition: Partial<Record<'schema' | 'isArray' | 'enumName', any>>, decoratorOptions: Partial<Record<'enum' | 'enumName', any>>): void;
|
|
5
|
+
export declare function addEnumSchema(paramDefinition: Partial<Record<string, any>>, decoratorOptions: Partial<Record<string, any>>): void;
|
|
6
|
+
export declare const isEnumArray: <T extends Partial<Record<"enum" | "isArray", any>>>(obj: Record<string, any>) => obj is T;
|
|
7
|
+
export declare const isEnumDefined: <T extends Partial<Record<"enum", any>>>(obj: Record<string, any>) => obj is T;
|
|
8
|
+
export declare const isEnumMetadata: (metadata: SchemaObjectMetadata) => any;
|
|
9
|
+
//# sourceMappingURL=enum.utils.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEnumMetadata = exports.isEnumDefined = exports.isEnumArray = exports.addEnumSchema = exports.addEnumArraySchema = exports.getEnumType = exports.getEnumValues = void 0;
|
|
4
|
+
function getEnumValues(enumType) {
|
|
5
|
+
if (Array.isArray(enumType)) {
|
|
6
|
+
return enumType;
|
|
7
|
+
}
|
|
8
|
+
if (typeof enumType !== 'object') {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const values = [];
|
|
12
|
+
const uniqueValues = {};
|
|
13
|
+
for (const key in enumType) {
|
|
14
|
+
const value = enumType[key];
|
|
15
|
+
/* eslint-disable no-prototype-builtins */
|
|
16
|
+
// filter out cases where enum key also becomes its value (A: B, B: A)
|
|
17
|
+
if (!uniqueValues.hasOwnProperty(value) &&
|
|
18
|
+
!uniqueValues.hasOwnProperty(key)) {
|
|
19
|
+
values.push(value);
|
|
20
|
+
uniqueValues[value] = value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return values;
|
|
24
|
+
}
|
|
25
|
+
exports.getEnumValues = getEnumValues;
|
|
26
|
+
function getEnumType(values) {
|
|
27
|
+
const hasString = values.filter(s => typeof s === 'string').length > 0;
|
|
28
|
+
return hasString ? 'string' : 'number';
|
|
29
|
+
}
|
|
30
|
+
exports.getEnumType = getEnumType;
|
|
31
|
+
function addEnumArraySchema(paramDefinition, decoratorOptions) {
|
|
32
|
+
const paramSchema = paramDefinition.schema || {};
|
|
33
|
+
paramDefinition.schema = paramSchema;
|
|
34
|
+
paramSchema.type = 'array';
|
|
35
|
+
delete paramDefinition.isArray;
|
|
36
|
+
const enumValues = getEnumValues(decoratorOptions.enum);
|
|
37
|
+
paramSchema.items = {
|
|
38
|
+
type: getEnumType(enumValues),
|
|
39
|
+
enum: enumValues,
|
|
40
|
+
};
|
|
41
|
+
if (decoratorOptions.enumName) {
|
|
42
|
+
paramDefinition.enumName = decoratorOptions.enumName;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.addEnumArraySchema = addEnumArraySchema;
|
|
46
|
+
function addEnumSchema(paramDefinition, decoratorOptions) {
|
|
47
|
+
const paramSchema = paramDefinition.schema || {};
|
|
48
|
+
const enumValues = getEnumValues(decoratorOptions.enum);
|
|
49
|
+
paramDefinition.schema = paramSchema;
|
|
50
|
+
paramSchema.enum = enumValues;
|
|
51
|
+
paramSchema.type = getEnumType(enumValues);
|
|
52
|
+
if (decoratorOptions.enumName) {
|
|
53
|
+
paramDefinition.enumName = decoratorOptions.enumName;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.addEnumSchema = addEnumSchema;
|
|
57
|
+
const isEnumArray = (obj) => obj.isArray && obj.enum;
|
|
58
|
+
exports.isEnumArray = isEnumArray;
|
|
59
|
+
const isEnumDefined = (obj) => obj.enum;
|
|
60
|
+
exports.isEnumDefined = isEnumDefined;
|
|
61
|
+
const isEnumMetadata = (metadata) => { var _a; return metadata.enum || (metadata.isArray && ((_a = metadata.items) === null || _a === void 0 ? void 0 : _a['enum'])); };
|
|
62
|
+
exports.isEnumMetadata = isEnumMetadata;
|
|
63
|
+
//# sourceMappingURL=enum.utils.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare enum HttpStatus {
|
|
2
|
+
CONTINUE = 100,
|
|
3
|
+
SWITCHING_PROTOCOLS = 101,
|
|
4
|
+
PROCESSING = 102,
|
|
5
|
+
EARLYHINTS = 103,
|
|
6
|
+
OK = 200,
|
|
7
|
+
CREATED = 201,
|
|
8
|
+
ACCEPTED = 202,
|
|
9
|
+
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
10
|
+
NO_CONTENT = 204,
|
|
11
|
+
RESET_CONTENT = 205,
|
|
12
|
+
PARTIAL_CONTENT = 206,
|
|
13
|
+
AMBIGUOUS = 300,
|
|
14
|
+
MOVED_PERMANENTLY = 301,
|
|
15
|
+
FOUND = 302,
|
|
16
|
+
SEE_OTHER = 303,
|
|
17
|
+
NOT_MODIFIED = 304,
|
|
18
|
+
TEMPORARY_REDIRECT = 307,
|
|
19
|
+
PERMANENT_REDIRECT = 308,
|
|
20
|
+
BAD_REQUEST = 400,
|
|
21
|
+
UNAUTHORIZED = 401,
|
|
22
|
+
PAYMENT_REQUIRED = 402,
|
|
23
|
+
FORBIDDEN = 403,
|
|
24
|
+
NOT_FOUND = 404,
|
|
25
|
+
METHOD_NOT_ALLOWED = 405,
|
|
26
|
+
NOT_ACCEPTABLE = 406,
|
|
27
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
28
|
+
REQUEST_TIMEOUT = 408,
|
|
29
|
+
CONFLICT = 409,
|
|
30
|
+
GONE = 410,
|
|
31
|
+
LENGTH_REQUIRED = 411,
|
|
32
|
+
PRECONDITION_FAILED = 412,
|
|
33
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
34
|
+
URI_TOO_LONG = 414,
|
|
35
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
36
|
+
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
37
|
+
EXPECTATION_FAILED = 417,
|
|
38
|
+
I_AM_A_TEAPOT = 418,
|
|
39
|
+
MISDIRECTED = 421,
|
|
40
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
41
|
+
FAILED_DEPENDENCY = 424,
|
|
42
|
+
PRECONDITION_REQUIRED = 428,
|
|
43
|
+
TOO_MANY_REQUESTS = 429,
|
|
44
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
45
|
+
NOT_IMPLEMENTED = 501,
|
|
46
|
+
BAD_GATEWAY = 502,
|
|
47
|
+
SERVICE_UNAVAILABLE = 503,
|
|
48
|
+
GATEWAY_TIMEOUT = 504,
|
|
49
|
+
HTTP_VERSION_NOT_SUPPORTED = 505
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=httpStatus.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpStatus = void 0;
|
|
4
|
+
var HttpStatus;
|
|
5
|
+
(function (HttpStatus) {
|
|
6
|
+
HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
|
|
7
|
+
HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
8
|
+
HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
|
|
9
|
+
HttpStatus[HttpStatus["EARLYHINTS"] = 103] = "EARLYHINTS";
|
|
10
|
+
HttpStatus[HttpStatus["OK"] = 200] = "OK";
|
|
11
|
+
HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
|
|
12
|
+
HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
|
|
13
|
+
HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
14
|
+
HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
15
|
+
HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
16
|
+
HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
17
|
+
HttpStatus[HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
|
|
18
|
+
HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
19
|
+
HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
|
|
20
|
+
HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
21
|
+
HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
22
|
+
HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
23
|
+
HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
24
|
+
HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
25
|
+
HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
26
|
+
HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
27
|
+
HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
28
|
+
HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
29
|
+
HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
30
|
+
HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
31
|
+
HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
32
|
+
HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
33
|
+
HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
|
|
34
|
+
HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
|
|
35
|
+
HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
36
|
+
HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
37
|
+
HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
38
|
+
HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
39
|
+
HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
40
|
+
HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
41
|
+
HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
42
|
+
HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
43
|
+
HttpStatus[HttpStatus["MISDIRECTED"] = 421] = "MISDIRECTED";
|
|
44
|
+
HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
45
|
+
HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
46
|
+
HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
47
|
+
HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
48
|
+
HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
49
|
+
HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
50
|
+
HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
51
|
+
HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
52
|
+
HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
53
|
+
HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
54
|
+
})(HttpStatus = exports.HttpStatus || (exports.HttpStatus = {}));
|
|
55
|
+
//# sourceMappingURL=httpStatus.js.map
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
title: string;
|
|
4
|
-
description: string;
|
|
5
|
-
version: string;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
1
|
+
import { SwaggerOptions } from '../interfaces';
|
|
2
|
+
export declare const swagger: SwaggerOptions;
|
|
9
3
|
//# sourceMappingURL=config.default.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
exports.swagger = void 0;
|
|
4
|
+
exports.swagger = {
|
|
5
|
+
title: 'My Project',
|
|
6
|
+
description: 'This is a swagger-ui for midwayjs project',
|
|
7
|
+
version: '1.0.0',
|
|
8
|
+
swaggerPath: '/swagger-ui',
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=config.default.js.map
|
package/dist/configuration.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ILifeCycle, IMidwayContainer, MidwayApplicationManager } from '@midwayjs/core';
|
|
2
|
+
export declare class SwaggerConfiguration implements ILifeCycle {
|
|
3
|
+
applicationManager: MidwayApplicationManager;
|
|
4
|
+
onReady(container: IMidwayContainer): Promise<void>;
|
|
3
5
|
}
|
|
4
6
|
//# sourceMappingURL=configuration.d.ts.map
|
package/dist/configuration.js
CHANGED
|
@@ -5,23 +5,39 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
12
|
+
exports.SwaggerConfiguration = void 0;
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
10
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
11
|
-
const
|
|
12
|
-
|
|
15
|
+
const _1 = require(".");
|
|
16
|
+
const DefaultConfig = require("./config/config.default");
|
|
17
|
+
let SwaggerConfiguration = class SwaggerConfiguration {
|
|
13
18
|
async onReady(container) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
this.applicationManager
|
|
20
|
+
.getApplications(['express', 'koa', 'egg', 'faas'])
|
|
21
|
+
.forEach(app => {
|
|
22
|
+
app.useMiddleware(_1.SwaggerMiddleware);
|
|
23
|
+
});
|
|
24
|
+
const explorer = await container.getAsync(_1.SwaggerExplorer);
|
|
25
|
+
explorer.scanApp();
|
|
18
26
|
}
|
|
19
27
|
};
|
|
20
|
-
|
|
21
|
-
decorator_1.
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, decorator_1.Inject)(),
|
|
30
|
+
__metadata("design:type", core_1.MidwayApplicationManager)
|
|
31
|
+
], SwaggerConfiguration.prototype, "applicationManager", void 0);
|
|
32
|
+
SwaggerConfiguration = __decorate([
|
|
33
|
+
(0, decorator_1.Configuration)({
|
|
34
|
+
importConfigs: [
|
|
35
|
+
{
|
|
36
|
+
default: DefaultConfig,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
22
39
|
namespace: 'swagger',
|
|
23
|
-
importConfigs: [path_1.join(__dirname, 'config')],
|
|
24
40
|
})
|
|
25
|
-
],
|
|
26
|
-
exports.
|
|
41
|
+
], SwaggerConfiguration);
|
|
42
|
+
exports.SwaggerConfiguration = SwaggerConfiguration;
|
|
27
43
|
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const DECORATORS_PREFIX = "swagger";
|
|
2
|
+
export declare const DECORATORS: {
|
|
3
|
+
API_OPERATION: string;
|
|
4
|
+
API_RESPONSE: string;
|
|
5
|
+
API_TAGS: string;
|
|
6
|
+
API_PARAMETERS: string;
|
|
7
|
+
API_HEADERS: string;
|
|
8
|
+
API_MODEL_PROPERTIES: string;
|
|
9
|
+
API_MODEL_PROPERTIES_ARRAY: string;
|
|
10
|
+
API_SECURITY: string;
|
|
11
|
+
API_EXCLUDE_ENDPOINT: string;
|
|
12
|
+
API_EXCLUDE_CONTROLLER: string;
|
|
13
|
+
API_EXTENSION: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DECORATORS = exports.DECORATORS_PREFIX = void 0;
|
|
4
|
+
exports.DECORATORS_PREFIX = 'swagger';
|
|
5
|
+
exports.DECORATORS = {
|
|
6
|
+
API_OPERATION: `${exports.DECORATORS_PREFIX}/apiOperation`,
|
|
7
|
+
API_RESPONSE: `${exports.DECORATORS_PREFIX}/apiResponse`,
|
|
8
|
+
API_TAGS: `${exports.DECORATORS_PREFIX}/apiUseTags`,
|
|
9
|
+
API_PARAMETERS: `${exports.DECORATORS_PREFIX}/apiParameters`,
|
|
10
|
+
API_HEADERS: `${exports.DECORATORS_PREFIX}/apiHeaders`,
|
|
11
|
+
API_MODEL_PROPERTIES: `${exports.DECORATORS_PREFIX}/apiModelProperties`,
|
|
12
|
+
API_MODEL_PROPERTIES_ARRAY: `${exports.DECORATORS_PREFIX}/apiModelPropertiesArray`,
|
|
13
|
+
API_SECURITY: `${exports.DECORATORS_PREFIX}/apiSecurity`,
|
|
14
|
+
API_EXCLUDE_ENDPOINT: `${exports.DECORATORS_PREFIX}/apiExcludeEndpoint`,
|
|
15
|
+
API_EXCLUDE_CONTROLLER: `${exports.DECORATORS_PREFIX}/apiExcludeController`,
|
|
16
|
+
API_EXTENSION: `${exports.DECORATORS_PREFIX}/apiExtension`,
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiBasicAuth = void 0;
|
|
4
|
+
const api_security_decorator_1 = require("./api-security.decorator");
|
|
5
|
+
function ApiBasicAuth(name = 'basic') {
|
|
6
|
+
return (0, api_security_decorator_1.ApiSecurity)(name);
|
|
7
|
+
}
|
|
8
|
+
exports.ApiBasicAuth = ApiBasicAuth;
|
|
9
|
+
//# sourceMappingURL=api-basic.decorator.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiBearerAuth = void 0;
|
|
4
|
+
const api_security_decorator_1 = require("./api-security.decorator");
|
|
5
|
+
function ApiBearerAuth(name = 'bearer') {
|
|
6
|
+
return (0, api_security_decorator_1.ApiSecurity)(name);
|
|
7
|
+
}
|
|
8
|
+
exports.ApiBearerAuth = ApiBearerAuth;
|
|
9
|
+
//# sourceMappingURL=api-bearer.decorator.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ContentObject, ExamplesObject, ReferenceObject, RequestBodyObject, SchemaObject, SwaggerEnumType } from '../interfaces';
|
|
2
|
+
declare type RequestBodyOptions = Omit<RequestBodyObject, 'content'>;
|
|
3
|
+
interface ApiBodyMetadata extends RequestBodyOptions {
|
|
4
|
+
type?: any;
|
|
5
|
+
isArray?: boolean;
|
|
6
|
+
enum?: SwaggerEnumType;
|
|
7
|
+
content?: ContentObject;
|
|
8
|
+
}
|
|
9
|
+
interface ApiBodySchemaHost extends RequestBodyOptions {
|
|
10
|
+
schema: SchemaObject | ReferenceObject;
|
|
11
|
+
examples?: ExamplesObject;
|
|
12
|
+
}
|
|
13
|
+
export declare type ApiBodyOptions = ApiBodyMetadata | ApiBodySchemaHost;
|
|
14
|
+
export declare function ApiBody(options: ApiBodyOptions): MethodDecorator;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=api-body.decorator.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiBody = void 0;
|
|
4
|
+
const enum_utils_1 = require("../common/enum.utils");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const defaultBodyMetadata = {
|
|
7
|
+
type: String,
|
|
8
|
+
required: true,
|
|
9
|
+
};
|
|
10
|
+
function ApiBody(options) {
|
|
11
|
+
const [type, isArray] = (0, helpers_1.getTypeIsArrayTuple)(options.type, options.isArray);
|
|
12
|
+
const param = {
|
|
13
|
+
in: 'body',
|
|
14
|
+
...options,
|
|
15
|
+
type,
|
|
16
|
+
isArray,
|
|
17
|
+
};
|
|
18
|
+
if ((0, enum_utils_1.isEnumArray)(options)) {
|
|
19
|
+
(0, enum_utils_1.addEnumArraySchema)(param, options);
|
|
20
|
+
}
|
|
21
|
+
else if ((0, enum_utils_1.isEnumDefined)(options)) {
|
|
22
|
+
(0, enum_utils_1.addEnumSchema)(param, options);
|
|
23
|
+
}
|
|
24
|
+
return (0, helpers_1.createParamDecorator)(param, defaultBodyMetadata);
|
|
25
|
+
}
|
|
26
|
+
exports.ApiBody = ApiBody;
|
|
27
|
+
//# sourceMappingURL=api-body.decorator.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiCookieAuth = void 0;
|
|
4
|
+
const api_security_decorator_1 = require("./api-security.decorator");
|
|
5
|
+
function ApiCookieAuth(name = 'cookie') {
|
|
6
|
+
return (0, api_security_decorator_1.ApiSecurity)(name);
|
|
7
|
+
}
|
|
8
|
+
exports.ApiCookieAuth = ApiCookieAuth;
|
|
9
|
+
//# sourceMappingURL=api-cookie.decorator.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExcludeController = void 0;
|
|
4
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function ApiExcludeController(disable = true) {
|
|
7
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_EXCLUDE_CONTROLLER, [
|
|
8
|
+
disable,
|
|
9
|
+
]);
|
|
10
|
+
}
|
|
11
|
+
exports.ApiExcludeController = ApiExcludeController;
|
|
12
|
+
//# sourceMappingURL=api-exclude-controller.decorator.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExcludeEndpoint = void 0;
|
|
4
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function ApiExcludeEndpoint(disable = true) {
|
|
7
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_EXCLUDE_ENDPOINT, {
|
|
8
|
+
disable,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
exports.ApiExcludeEndpoint = ApiExcludeEndpoint;
|
|
12
|
+
//# sourceMappingURL=api-exclude-endpoint.decorator.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiExtension = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
function ApiExtension(extensionKey, extensionProperties) {
|
|
7
|
+
if (!extensionKey.startsWith('x-')) {
|
|
8
|
+
throw new Error('Extension key is not prefixed. Please ensure you prefix it with `x-`.');
|
|
9
|
+
}
|
|
10
|
+
const extensionObject = {
|
|
11
|
+
[extensionKey]: JSON.parse(JSON.stringify(extensionProperties)),
|
|
12
|
+
};
|
|
13
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_EXTENSION, extensionObject);
|
|
14
|
+
}
|
|
15
|
+
exports.ApiExtension = ApiExtension;
|
|
16
|
+
//# sourceMappingURL=api-extension.decorator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SwaggerEnumType, ParameterObject } from '../interfaces';
|
|
2
|
+
export interface ApiHeaderOptions extends Omit<ParameterObject, 'in'> {
|
|
3
|
+
enum?: SwaggerEnumType;
|
|
4
|
+
}
|
|
5
|
+
export declare function ApiHeader(options: ApiHeaderOptions): any;
|
|
6
|
+
export declare const ApiHeaders: (headers: ApiHeaderOptions[]) => MethodDecorator & ClassDecorator;
|
|
7
|
+
//# sourceMappingURL=api-header.decorator.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiHeaders = exports.ApiHeader = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const enum_utils_1 = require("../common/enum.utils");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
8
|
+
const defaultHeaderOptions = {
|
|
9
|
+
name: '',
|
|
10
|
+
};
|
|
11
|
+
function ApiHeader(options) {
|
|
12
|
+
const param = {
|
|
13
|
+
name: !options.name ? defaultHeaderOptions.name : options.name,
|
|
14
|
+
in: 'header',
|
|
15
|
+
description: options.description,
|
|
16
|
+
required: options.required,
|
|
17
|
+
schema: {
|
|
18
|
+
...(options.schema || {}),
|
|
19
|
+
type: 'string',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
if (options.enum) {
|
|
23
|
+
const enumValues = (0, enum_utils_1.getEnumValues)(options.enum);
|
|
24
|
+
param.schema = {
|
|
25
|
+
enum: enumValues,
|
|
26
|
+
type: (0, enum_utils_1.getEnumType)(enumValues),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return (target, key, descriptor) => {
|
|
30
|
+
if (descriptor) {
|
|
31
|
+
return (0, helpers_1.createParamDecorator)(param, defaultHeaderOptions)(target, key, descriptor);
|
|
32
|
+
}
|
|
33
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_HEADERS, param)(target, undefined, undefined);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.ApiHeader = ApiHeader;
|
|
37
|
+
const ApiHeaders = (headers) => {
|
|
38
|
+
return (target, key, descriptor) => {
|
|
39
|
+
headers.forEach(options => ApiHeader(options)(target, key, descriptor));
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.ApiHeaders = ApiHeaders;
|
|
43
|
+
//# sourceMappingURL=api-header.decorator.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiOAuth2 = void 0;
|
|
4
|
+
const api_security_decorator_1 = require("./api-security.decorator");
|
|
5
|
+
function ApiOAuth2(scopes, name = 'oauth2') {
|
|
6
|
+
return (0, api_security_decorator_1.ApiSecurity)(name, scopes);
|
|
7
|
+
}
|
|
8
|
+
exports.ApiOAuth2 = ApiOAuth2;
|
|
9
|
+
//# sourceMappingURL=api-oauth2.decorator.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiOperation = void 0;
|
|
4
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const defaultOperationOptions = {
|
|
7
|
+
summary: '',
|
|
8
|
+
};
|
|
9
|
+
function ApiOperation(options) {
|
|
10
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_OPERATION, {
|
|
11
|
+
...defaultOperationOptions,
|
|
12
|
+
...options,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.ApiOperation = ApiOperation;
|
|
16
|
+
//# sourceMappingURL=api-operation.decorator.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Type, ParameterObject, SchemaObject, SwaggerEnumType } from '../interfaces';
|
|
2
|
+
declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema'>;
|
|
3
|
+
interface ApiParamMetadata extends ParameterOptions {
|
|
4
|
+
type?: Type | string;
|
|
5
|
+
format?: string;
|
|
6
|
+
enum?: SwaggerEnumType;
|
|
7
|
+
enumName?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ApiParamSchemaHost extends ParameterOptions {
|
|
10
|
+
schema: SchemaObject;
|
|
11
|
+
}
|
|
12
|
+
export declare type ApiParamOptions = ApiParamMetadata | ApiParamSchemaHost;
|
|
13
|
+
export declare function ApiParam(options: ApiParamOptions): MethodDecorator;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=api-param.decorator.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiParam = void 0;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
const enum_utils_1 = require("../common/enum.utils");
|
|
6
|
+
const defaultParamOptions = {
|
|
7
|
+
name: '',
|
|
8
|
+
required: true,
|
|
9
|
+
};
|
|
10
|
+
function ApiParam(options) {
|
|
11
|
+
const param = {
|
|
12
|
+
name: !options.name ? defaultParamOptions.name : options.name,
|
|
13
|
+
in: 'path',
|
|
14
|
+
...options,
|
|
15
|
+
};
|
|
16
|
+
const apiParamMetadata = options;
|
|
17
|
+
if (apiParamMetadata.enum) {
|
|
18
|
+
param.schema = param.schema || {};
|
|
19
|
+
const paramSchema = param.schema;
|
|
20
|
+
const enumValues = (0, enum_utils_1.getEnumValues)(apiParamMetadata.enum);
|
|
21
|
+
paramSchema.type = (0, enum_utils_1.getEnumType)(enumValues);
|
|
22
|
+
paramSchema.enum = enumValues;
|
|
23
|
+
if (apiParamMetadata.enumName) {
|
|
24
|
+
param.enumName = apiParamMetadata.enumName;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return (0, helpers_1.createParamDecorator)(param, defaultParamOptions);
|
|
28
|
+
}
|
|
29
|
+
exports.ApiParam = ApiParam;
|
|
30
|
+
//# sourceMappingURL=api-param.decorator.js.map
|