@midwayjs/swagger 1.3.0 → 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 +27 -11
- 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 +8 -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 +13 -12
- package/CHANGELOG.md +0 -121
- package/dist/controller/swagger.d.ts +0 -31
- package/dist/controller/swagger.js +0 -96
- package/dist/interface.d.ts +0 -16
- package/dist/interface.js +0 -3
- package/dist/lib/createAPI.d.ts +0 -52
- 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 -31
- package/dist/lib/generator.js +0 -310
- package/dist/service/generator.d.ts +0 -24
- package/dist/service/generator.js +0 -37
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SchemaObjectMetadata } from '../interfaces';
|
|
2
|
+
export interface ApiPropertyOptions extends Omit<SchemaObjectMetadata, 'name' | 'enum'> {
|
|
3
|
+
name?: string;
|
|
4
|
+
enum?: any[] | Record<string, any>;
|
|
5
|
+
enumName?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function ApiProperty(options?: ApiPropertyOptions): PropertyDecorator;
|
|
8
|
+
export declare function createApiPropertyDecorator(options?: ApiPropertyOptions): PropertyDecorator;
|
|
9
|
+
export declare function ApiPropertyOptional(options?: ApiPropertyOptions): PropertyDecorator;
|
|
10
|
+
export declare function ApiResponseProperty(options?: Pick<ApiPropertyOptions, 'type' | 'example' | 'format' | 'enum' | 'deprecated'>): PropertyDecorator;
|
|
11
|
+
//# sourceMappingURL=api-property.decorator.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiResponseProperty = exports.ApiPropertyOptional = exports.createApiPropertyDecorator = exports.ApiProperty = 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 isEnumArray = (obj) => obj.isArray && !!obj.enum;
|
|
8
|
+
function ApiProperty(options = {}) {
|
|
9
|
+
return createApiPropertyDecorator(options);
|
|
10
|
+
}
|
|
11
|
+
exports.ApiProperty = ApiProperty;
|
|
12
|
+
function createApiPropertyDecorator(options = {}) {
|
|
13
|
+
const [type, isArray] = (0, helpers_1.getTypeIsArrayTuple)(options.type, options.isArray);
|
|
14
|
+
options = {
|
|
15
|
+
...options,
|
|
16
|
+
type,
|
|
17
|
+
isArray,
|
|
18
|
+
};
|
|
19
|
+
if (isEnumArray(options)) {
|
|
20
|
+
options.type = 'array';
|
|
21
|
+
const enumValues = (0, enum_utils_1.getEnumValues)(options.enum);
|
|
22
|
+
options.items = {
|
|
23
|
+
type: (0, enum_utils_1.getEnumType)(enumValues),
|
|
24
|
+
enum: enumValues,
|
|
25
|
+
};
|
|
26
|
+
delete options.enum;
|
|
27
|
+
}
|
|
28
|
+
else if (options.enum) {
|
|
29
|
+
const enumValues = (0, enum_utils_1.getEnumValues)(options.enum);
|
|
30
|
+
options.enum = enumValues;
|
|
31
|
+
options.type = (0, enum_utils_1.getEnumType)(enumValues);
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(options.type)) {
|
|
34
|
+
options.type = 'array';
|
|
35
|
+
options.items = {
|
|
36
|
+
type: options.type[0],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return (0, helpers_1.createPropertyDecorator)(constants_1.DECORATORS.API_MODEL_PROPERTIES, options);
|
|
40
|
+
}
|
|
41
|
+
exports.createApiPropertyDecorator = createApiPropertyDecorator;
|
|
42
|
+
function ApiPropertyOptional(options = {}) {
|
|
43
|
+
return ApiProperty({
|
|
44
|
+
...options,
|
|
45
|
+
required: false,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
exports.ApiPropertyOptional = ApiPropertyOptional;
|
|
49
|
+
function ApiResponseProperty(options = {}) {
|
|
50
|
+
return ApiProperty({
|
|
51
|
+
readOnly: true,
|
|
52
|
+
...options,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.ApiResponseProperty = ApiResponseProperty;
|
|
56
|
+
//# sourceMappingURL=api-property.decorator.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Type, ParameterObject, ReferenceObject, SchemaObject, SwaggerEnumType } from '../interfaces';
|
|
2
|
+
declare type ParameterOptions = Omit<ParameterObject, 'in' | 'schema' | 'name'>;
|
|
3
|
+
interface ApiQueryMetadata extends ParameterOptions {
|
|
4
|
+
name?: string;
|
|
5
|
+
type?: Type | string;
|
|
6
|
+
isArray?: boolean;
|
|
7
|
+
enum?: SwaggerEnumType;
|
|
8
|
+
enumName?: string;
|
|
9
|
+
}
|
|
10
|
+
interface ApiQuerySchemaHost extends ParameterOptions {
|
|
11
|
+
name?: string;
|
|
12
|
+
schema: SchemaObject | ReferenceObject;
|
|
13
|
+
}
|
|
14
|
+
export declare type ApiQueryOptions = ApiQueryMetadata | ApiQuerySchemaHost;
|
|
15
|
+
export declare function ApiQuery(options: ApiQueryOptions): MethodDecorator;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=api-query.decorator.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiQuery = void 0;
|
|
4
|
+
const enum_utils_1 = require("../common/enum.utils");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const defaultQueryOptions = {
|
|
7
|
+
name: '',
|
|
8
|
+
required: true,
|
|
9
|
+
};
|
|
10
|
+
function ApiQuery(options) {
|
|
11
|
+
const apiQueryMetadata = options;
|
|
12
|
+
const [type, isArray] = (0, helpers_1.getTypeIsArrayTuple)(apiQueryMetadata.type, apiQueryMetadata.isArray);
|
|
13
|
+
const param = {
|
|
14
|
+
name: !options.name ? defaultQueryOptions.name : options.name,
|
|
15
|
+
in: 'query',
|
|
16
|
+
...options,
|
|
17
|
+
type,
|
|
18
|
+
};
|
|
19
|
+
if ((0, enum_utils_1.isEnumArray)(options)) {
|
|
20
|
+
(0, enum_utils_1.addEnumArraySchema)(param, options);
|
|
21
|
+
}
|
|
22
|
+
else if ((0, enum_utils_1.isEnumDefined)(options)) {
|
|
23
|
+
(0, enum_utils_1.addEnumSchema)(param, options);
|
|
24
|
+
}
|
|
25
|
+
if (isArray) {
|
|
26
|
+
param.isArray = isArray;
|
|
27
|
+
}
|
|
28
|
+
return (0, helpers_1.createParamDecorator)(param, defaultQueryOptions);
|
|
29
|
+
}
|
|
30
|
+
exports.ApiQuery = ApiQuery;
|
|
31
|
+
//# sourceMappingURL=api-query.decorator.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ResponseObject, SchemaObject, ReferenceObject, Type } from '../interfaces';
|
|
2
|
+
export interface ApiResponseMetadata extends Omit<ResponseObject, 'description'> {
|
|
3
|
+
status?: number | 'default';
|
|
4
|
+
type?: Type | string | Record<string, any>;
|
|
5
|
+
isArray?: boolean;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ApiResponseSchemaHost extends Omit<ResponseObject, 'description'> {
|
|
9
|
+
schema: SchemaObject & Partial<ReferenceObject>;
|
|
10
|
+
status?: number;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare type ApiResponseOptions = ApiResponseMetadata | ApiResponseSchemaHost;
|
|
14
|
+
export declare function ApiResponse(options: ApiResponseOptions): any;
|
|
15
|
+
export declare const ApiOkResponse: (options?: ApiResponseOptions) => any;
|
|
16
|
+
export declare const ApiCreatedResponse: (options?: ApiResponseOptions) => any;
|
|
17
|
+
export declare const ApiAcceptedResponse: (options?: ApiResponseOptions) => any;
|
|
18
|
+
export declare const ApiNoContentResponse: (options?: ApiResponseOptions) => any;
|
|
19
|
+
export declare const ApiMovedPermanentlyResponse: (options?: ApiResponseOptions) => any;
|
|
20
|
+
export declare const ApiFoundResponse: (options?: ApiResponseOptions) => any;
|
|
21
|
+
export declare const ApiBadRequestResponse: (options?: ApiResponseOptions) => any;
|
|
22
|
+
export declare const ApiUnauthorizedResponse: (options?: ApiResponseOptions) => any;
|
|
23
|
+
export declare const ApiTooManyRequestsResponse: (options?: ApiResponseOptions) => any;
|
|
24
|
+
export declare const ApiNotFoundResponse: (options?: ApiResponseOptions) => any;
|
|
25
|
+
export declare const ApiInternalServerErrorResponse: (options?: ApiResponseOptions) => any;
|
|
26
|
+
export declare const ApiBadGatewayResponse: (options?: ApiResponseOptions) => any;
|
|
27
|
+
export declare const ApiConflictResponse: (options?: ApiResponseOptions) => any;
|
|
28
|
+
export declare const ApiForbiddenResponse: (options?: ApiResponseOptions) => any;
|
|
29
|
+
export declare const ApiGatewayTimeoutResponse: (options?: ApiResponseOptions) => any;
|
|
30
|
+
export declare const ApiGoneResponse: (options?: ApiResponseOptions) => any;
|
|
31
|
+
export declare const ApiMethodNotAllowedResponse: (options?: ApiResponseOptions) => any;
|
|
32
|
+
export declare const ApiNotAcceptableResponse: (options?: ApiResponseOptions) => any;
|
|
33
|
+
export declare const ApiNotImplementedResponse: (options?: ApiResponseOptions) => any;
|
|
34
|
+
export declare const ApiPreconditionFailedResponse: (options?: ApiResponseOptions) => any;
|
|
35
|
+
export declare const ApiPayloadTooLargeResponse: (options?: ApiResponseOptions) => any;
|
|
36
|
+
export declare const ApiRequestTimeoutResponse: (options?: ApiResponseOptions) => any;
|
|
37
|
+
export declare const ApiServiceUnavailableResponse: (options?: ApiResponseOptions) => any;
|
|
38
|
+
export declare const ApiUnprocessableEntityResponse: (options?: ApiResponseOptions) => any;
|
|
39
|
+
export declare const ApiUnsupportedMediaTypeResponse: (options?: ApiResponseOptions) => any;
|
|
40
|
+
export declare const ApiDefaultResponse: (options?: ApiResponseOptions) => any;
|
|
41
|
+
//# sourceMappingURL=api-response.decorator.d.ts.map
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiDefaultResponse = exports.ApiUnsupportedMediaTypeResponse = exports.ApiUnprocessableEntityResponse = exports.ApiServiceUnavailableResponse = exports.ApiRequestTimeoutResponse = exports.ApiPayloadTooLargeResponse = exports.ApiPreconditionFailedResponse = exports.ApiNotImplementedResponse = exports.ApiNotAcceptableResponse = exports.ApiMethodNotAllowedResponse = exports.ApiGoneResponse = exports.ApiGatewayTimeoutResponse = exports.ApiForbiddenResponse = exports.ApiConflictResponse = exports.ApiBadGatewayResponse = exports.ApiInternalServerErrorResponse = exports.ApiNotFoundResponse = exports.ApiTooManyRequestsResponse = exports.ApiUnauthorizedResponse = exports.ApiBadRequestResponse = exports.ApiFoundResponse = exports.ApiMovedPermanentlyResponse = exports.ApiNoContentResponse = exports.ApiAcceptedResponse = exports.ApiCreatedResponse = exports.ApiOkResponse = exports.ApiResponse = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const httpStatus_1 = require("../common/httpStatus");
|
|
7
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
8
|
+
function ApiResponse(options) {
|
|
9
|
+
const [type, isArray] = (0, helpers_1.getTypeIsArrayTuple)(options.type, options.isArray);
|
|
10
|
+
options.type = type;
|
|
11
|
+
options.isArray = isArray;
|
|
12
|
+
options.description = options.description ? options.description : '';
|
|
13
|
+
const groupedMetadata = {
|
|
14
|
+
[options.status || 'default']: options,
|
|
15
|
+
};
|
|
16
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_RESPONSE, groupedMetadata);
|
|
17
|
+
}
|
|
18
|
+
exports.ApiResponse = ApiResponse;
|
|
19
|
+
const ApiOkResponse = (options = {}) => ApiResponse({
|
|
20
|
+
...options,
|
|
21
|
+
status: httpStatus_1.HttpStatus.OK,
|
|
22
|
+
});
|
|
23
|
+
exports.ApiOkResponse = ApiOkResponse;
|
|
24
|
+
const ApiCreatedResponse = (options = {}) => ApiResponse({
|
|
25
|
+
...options,
|
|
26
|
+
status: httpStatus_1.HttpStatus.CREATED,
|
|
27
|
+
});
|
|
28
|
+
exports.ApiCreatedResponse = ApiCreatedResponse;
|
|
29
|
+
const ApiAcceptedResponse = (options = {}) => ApiResponse({
|
|
30
|
+
...options,
|
|
31
|
+
status: httpStatus_1.HttpStatus.ACCEPTED,
|
|
32
|
+
});
|
|
33
|
+
exports.ApiAcceptedResponse = ApiAcceptedResponse;
|
|
34
|
+
const ApiNoContentResponse = (options = {}) => ApiResponse({
|
|
35
|
+
...options,
|
|
36
|
+
status: httpStatus_1.HttpStatus.NO_CONTENT,
|
|
37
|
+
});
|
|
38
|
+
exports.ApiNoContentResponse = ApiNoContentResponse;
|
|
39
|
+
const ApiMovedPermanentlyResponse = (options = {}) => ApiResponse({
|
|
40
|
+
...options,
|
|
41
|
+
status: httpStatus_1.HttpStatus.MOVED_PERMANENTLY,
|
|
42
|
+
});
|
|
43
|
+
exports.ApiMovedPermanentlyResponse = ApiMovedPermanentlyResponse;
|
|
44
|
+
const ApiFoundResponse = (options = {}) => ApiResponse({
|
|
45
|
+
...options,
|
|
46
|
+
status: httpStatus_1.HttpStatus.FOUND,
|
|
47
|
+
});
|
|
48
|
+
exports.ApiFoundResponse = ApiFoundResponse;
|
|
49
|
+
const ApiBadRequestResponse = (options = {}) => ApiResponse({
|
|
50
|
+
...options,
|
|
51
|
+
status: httpStatus_1.HttpStatus.BAD_REQUEST,
|
|
52
|
+
});
|
|
53
|
+
exports.ApiBadRequestResponse = ApiBadRequestResponse;
|
|
54
|
+
const ApiUnauthorizedResponse = (options = {}) => ApiResponse({
|
|
55
|
+
...options,
|
|
56
|
+
status: httpStatus_1.HttpStatus.UNAUTHORIZED,
|
|
57
|
+
});
|
|
58
|
+
exports.ApiUnauthorizedResponse = ApiUnauthorizedResponse;
|
|
59
|
+
const ApiTooManyRequestsResponse = (options = {}) => ApiResponse({
|
|
60
|
+
...options,
|
|
61
|
+
status: httpStatus_1.HttpStatus.TOO_MANY_REQUESTS,
|
|
62
|
+
});
|
|
63
|
+
exports.ApiTooManyRequestsResponse = ApiTooManyRequestsResponse;
|
|
64
|
+
const ApiNotFoundResponse = (options = {}) => ApiResponse({
|
|
65
|
+
...options,
|
|
66
|
+
status: httpStatus_1.HttpStatus.NOT_FOUND,
|
|
67
|
+
});
|
|
68
|
+
exports.ApiNotFoundResponse = ApiNotFoundResponse;
|
|
69
|
+
const ApiInternalServerErrorResponse = (options = {}) => ApiResponse({
|
|
70
|
+
...options,
|
|
71
|
+
status: httpStatus_1.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
72
|
+
});
|
|
73
|
+
exports.ApiInternalServerErrorResponse = ApiInternalServerErrorResponse;
|
|
74
|
+
const ApiBadGatewayResponse = (options = {}) => ApiResponse({
|
|
75
|
+
...options,
|
|
76
|
+
status: httpStatus_1.HttpStatus.BAD_GATEWAY,
|
|
77
|
+
});
|
|
78
|
+
exports.ApiBadGatewayResponse = ApiBadGatewayResponse;
|
|
79
|
+
const ApiConflictResponse = (options = {}) => ApiResponse({
|
|
80
|
+
...options,
|
|
81
|
+
status: httpStatus_1.HttpStatus.CONFLICT,
|
|
82
|
+
});
|
|
83
|
+
exports.ApiConflictResponse = ApiConflictResponse;
|
|
84
|
+
const ApiForbiddenResponse = (options = {}) => ApiResponse({
|
|
85
|
+
...options,
|
|
86
|
+
status: httpStatus_1.HttpStatus.FORBIDDEN,
|
|
87
|
+
});
|
|
88
|
+
exports.ApiForbiddenResponse = ApiForbiddenResponse;
|
|
89
|
+
const ApiGatewayTimeoutResponse = (options = {}) => ApiResponse({
|
|
90
|
+
...options,
|
|
91
|
+
status: httpStatus_1.HttpStatus.GATEWAY_TIMEOUT,
|
|
92
|
+
});
|
|
93
|
+
exports.ApiGatewayTimeoutResponse = ApiGatewayTimeoutResponse;
|
|
94
|
+
const ApiGoneResponse = (options = {}) => ApiResponse({
|
|
95
|
+
...options,
|
|
96
|
+
status: httpStatus_1.HttpStatus.GONE,
|
|
97
|
+
});
|
|
98
|
+
exports.ApiGoneResponse = ApiGoneResponse;
|
|
99
|
+
const ApiMethodNotAllowedResponse = (options = {}) => ApiResponse({
|
|
100
|
+
...options,
|
|
101
|
+
status: httpStatus_1.HttpStatus.METHOD_NOT_ALLOWED,
|
|
102
|
+
});
|
|
103
|
+
exports.ApiMethodNotAllowedResponse = ApiMethodNotAllowedResponse;
|
|
104
|
+
const ApiNotAcceptableResponse = (options = {}) => ApiResponse({
|
|
105
|
+
...options,
|
|
106
|
+
status: httpStatus_1.HttpStatus.NOT_ACCEPTABLE,
|
|
107
|
+
});
|
|
108
|
+
exports.ApiNotAcceptableResponse = ApiNotAcceptableResponse;
|
|
109
|
+
const ApiNotImplementedResponse = (options = {}) => ApiResponse({
|
|
110
|
+
...options,
|
|
111
|
+
status: httpStatus_1.HttpStatus.NOT_IMPLEMENTED,
|
|
112
|
+
});
|
|
113
|
+
exports.ApiNotImplementedResponse = ApiNotImplementedResponse;
|
|
114
|
+
const ApiPreconditionFailedResponse = (options = {}) => ApiResponse({
|
|
115
|
+
...options,
|
|
116
|
+
status: httpStatus_1.HttpStatus.PRECONDITION_FAILED,
|
|
117
|
+
});
|
|
118
|
+
exports.ApiPreconditionFailedResponse = ApiPreconditionFailedResponse;
|
|
119
|
+
const ApiPayloadTooLargeResponse = (options = {}) => ApiResponse({
|
|
120
|
+
...options,
|
|
121
|
+
status: httpStatus_1.HttpStatus.PAYLOAD_TOO_LARGE,
|
|
122
|
+
});
|
|
123
|
+
exports.ApiPayloadTooLargeResponse = ApiPayloadTooLargeResponse;
|
|
124
|
+
const ApiRequestTimeoutResponse = (options = {}) => ApiResponse({
|
|
125
|
+
...options,
|
|
126
|
+
status: httpStatus_1.HttpStatus.REQUEST_TIMEOUT,
|
|
127
|
+
});
|
|
128
|
+
exports.ApiRequestTimeoutResponse = ApiRequestTimeoutResponse;
|
|
129
|
+
const ApiServiceUnavailableResponse = (options = {}) => ApiResponse({
|
|
130
|
+
...options,
|
|
131
|
+
status: httpStatus_1.HttpStatus.SERVICE_UNAVAILABLE,
|
|
132
|
+
});
|
|
133
|
+
exports.ApiServiceUnavailableResponse = ApiServiceUnavailableResponse;
|
|
134
|
+
const ApiUnprocessableEntityResponse = (options = {}) => ApiResponse({
|
|
135
|
+
...options,
|
|
136
|
+
status: httpStatus_1.HttpStatus.UNPROCESSABLE_ENTITY,
|
|
137
|
+
});
|
|
138
|
+
exports.ApiUnprocessableEntityResponse = ApiUnprocessableEntityResponse;
|
|
139
|
+
const ApiUnsupportedMediaTypeResponse = (options = {}) => ApiResponse({
|
|
140
|
+
...options,
|
|
141
|
+
status: httpStatus_1.HttpStatus.UNSUPPORTED_MEDIA_TYPE,
|
|
142
|
+
});
|
|
143
|
+
exports.ApiUnsupportedMediaTypeResponse = ApiUnsupportedMediaTypeResponse;
|
|
144
|
+
const ApiDefaultResponse = (options = {}) => ApiResponse({
|
|
145
|
+
...options,
|
|
146
|
+
status: 'default',
|
|
147
|
+
});
|
|
148
|
+
exports.ApiDefaultResponse = ApiDefaultResponse;
|
|
149
|
+
//# sourceMappingURL=api-response.decorator.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiSecurity = void 0;
|
|
4
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function ApiSecurity(name, requirements = []) {
|
|
7
|
+
let metadata;
|
|
8
|
+
if (typeof name === 'string') {
|
|
9
|
+
metadata = { [name]: requirements || [] };
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
metadata = name;
|
|
13
|
+
}
|
|
14
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_SECURITY, metadata);
|
|
15
|
+
}
|
|
16
|
+
exports.ApiSecurity = ApiSecurity;
|
|
17
|
+
//# sourceMappingURL=api-security.decorator.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiTags = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
function ApiTags(...tags) {
|
|
7
|
+
return (0, helpers_1.createMixedDecorator)(constants_1.DECORATORS.API_TAGS, tags);
|
|
8
|
+
}
|
|
9
|
+
exports.ApiTags = ApiTags;
|
|
10
|
+
//# sourceMappingURL=api-tags.decorator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Type } from '../interfaces';
|
|
2
|
+
export declare function createPropertyDecorator<T extends Record<string, any> = any>(metakey: string, metadata: T): PropertyDecorator;
|
|
3
|
+
export declare function createMixedDecorator<T = any>(metakey: string, metadata: T): any;
|
|
4
|
+
export declare function createParamDecorator<T extends Record<string, any> = any>(metadata: T, initial: Partial<T>): MethodDecorator;
|
|
5
|
+
export declare function getTypeIsArrayTuple(input: Type | undefined | string | Record<string, any>, isArrayFlag: boolean): [Type | undefined | string | Record<string, any>, boolean];
|
|
6
|
+
export declare function getSchemaPath(clzz: Type | string): string;
|
|
7
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSchemaPath = exports.getTypeIsArrayTuple = exports.createParamDecorator = exports.createMixedDecorator = exports.createPropertyDecorator = void 0;
|
|
4
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function createPropertyDecorator(metakey, metadata) {
|
|
7
|
+
return (0, decorator_1.createCustomPropertyDecorator)(metakey, metadata);
|
|
8
|
+
}
|
|
9
|
+
exports.createPropertyDecorator = createPropertyDecorator;
|
|
10
|
+
function createMixedDecorator(metakey, metadata) {
|
|
11
|
+
return (0, decorator_1.createCustomMethodDecorator)(metakey, metadata);
|
|
12
|
+
}
|
|
13
|
+
exports.createMixedDecorator = createMixedDecorator;
|
|
14
|
+
function createParamDecorator(metadata, initial) {
|
|
15
|
+
return (0, decorator_1.createCustomMethodDecorator)(constants_1.DECORATORS.API_PARAMETERS, {
|
|
16
|
+
...initial,
|
|
17
|
+
...metadata,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.createParamDecorator = createParamDecorator;
|
|
21
|
+
function getTypeIsArrayTuple(input, isArrayFlag) {
|
|
22
|
+
if (!input) {
|
|
23
|
+
return [input, isArrayFlag];
|
|
24
|
+
}
|
|
25
|
+
if (isArrayFlag) {
|
|
26
|
+
return [input, isArrayFlag];
|
|
27
|
+
}
|
|
28
|
+
const isInputArray = Array.isArray(input);
|
|
29
|
+
const type = isInputArray ? input[0] : input;
|
|
30
|
+
return [type, isInputArray];
|
|
31
|
+
}
|
|
32
|
+
exports.getTypeIsArrayTuple = getTypeIsArrayTuple;
|
|
33
|
+
function getSchemaPath(clzz) {
|
|
34
|
+
let str = clzz;
|
|
35
|
+
if (typeof clzz === 'object') {
|
|
36
|
+
str = clzz ? clzz.name : clzz;
|
|
37
|
+
}
|
|
38
|
+
return `#/components/schemas/${str}`;
|
|
39
|
+
}
|
|
40
|
+
exports.getSchemaPath = getSchemaPath;
|
|
41
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './api-body.decorator';
|
|
2
|
+
export * from './api-exclude-endpoint.decorator';
|
|
3
|
+
export * from './api-exclude-controller.decorator';
|
|
4
|
+
export * from './api-header.decorator';
|
|
5
|
+
export * from './api-operation.decorator';
|
|
6
|
+
export * from './api-param.decorator';
|
|
7
|
+
export { ApiProperty, ApiPropertyOptional, ApiPropertyOptions, ApiResponseProperty, } from './api-property.decorator';
|
|
8
|
+
export * from './api-query.decorator';
|
|
9
|
+
export * from './api-response.decorator';
|
|
10
|
+
export * from './api-tags.decorator';
|
|
11
|
+
export * from './api-extension.decorator';
|
|
12
|
+
export * from './api-basic.decorator';
|
|
13
|
+
export * from './api-bearer.decorator';
|
|
14
|
+
export * from './api-cookie.decorator';
|
|
15
|
+
export * from './api-oauth2.decorator';
|
|
16
|
+
export * from './api-security.decorator';
|
|
17
|
+
export { getSchemaPath } from './helpers';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.getSchemaPath = exports.ApiResponseProperty = exports.ApiPropertyOptional = exports.ApiProperty = void 0;
|
|
14
|
+
__exportStar(require("./api-body.decorator"), exports);
|
|
15
|
+
__exportStar(require("./api-exclude-endpoint.decorator"), exports);
|
|
16
|
+
__exportStar(require("./api-exclude-controller.decorator"), exports);
|
|
17
|
+
__exportStar(require("./api-header.decorator"), exports);
|
|
18
|
+
__exportStar(require("./api-operation.decorator"), exports);
|
|
19
|
+
__exportStar(require("./api-param.decorator"), exports);
|
|
20
|
+
var api_property_decorator_1 = require("./api-property.decorator");
|
|
21
|
+
Object.defineProperty(exports, "ApiProperty", { enumerable: true, get: function () { return api_property_decorator_1.ApiProperty; } });
|
|
22
|
+
Object.defineProperty(exports, "ApiPropertyOptional", { enumerable: true, get: function () { return api_property_decorator_1.ApiPropertyOptional; } });
|
|
23
|
+
Object.defineProperty(exports, "ApiResponseProperty", { enumerable: true, get: function () { return api_property_decorator_1.ApiResponseProperty; } });
|
|
24
|
+
__exportStar(require("./api-query.decorator"), exports);
|
|
25
|
+
__exportStar(require("./api-response.decorator"), exports);
|
|
26
|
+
__exportStar(require("./api-tags.decorator"), exports);
|
|
27
|
+
__exportStar(require("./api-extension.decorator"), exports);
|
|
28
|
+
__exportStar(require("./api-basic.decorator"), exports);
|
|
29
|
+
__exportStar(require("./api-bearer.decorator"), exports);
|
|
30
|
+
__exportStar(require("./api-cookie.decorator"), exports);
|
|
31
|
+
__exportStar(require("./api-oauth2.decorator"), exports);
|
|
32
|
+
__exportStar(require("./api-security.decorator"), exports);
|
|
33
|
+
var helpers_1 = require("./helpers");
|
|
34
|
+
Object.defineProperty(exports, "getSchemaPath", { enumerable: true, get: function () { return helpers_1.getSchemaPath; } });
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { OpenAPIObject, ExternalDocumentationObject, SecurityRequirementObject, SecuritySchemeObject, ServerVariableObject, PathItemObject, SchemaObject } from './interfaces';
|
|
2
|
+
export declare class DocumentBuilder {
|
|
3
|
+
private readonly document;
|
|
4
|
+
setTitle(title: string): this;
|
|
5
|
+
setDescription(description: string): this;
|
|
6
|
+
setVersion(version: string): this;
|
|
7
|
+
setTermsOfService(termsOfService: string): this;
|
|
8
|
+
setContact(name: string, url: string, email: string): this;
|
|
9
|
+
setLicense(name: string, url: string): this;
|
|
10
|
+
addServer(url: string, description?: string, variables?: Record<string, ServerVariableObject>): this;
|
|
11
|
+
setExternalDoc(description: string, url: string): this;
|
|
12
|
+
setBasePath(path: string): this;
|
|
13
|
+
addPaths(paths: Record<string, PathItemObject>): this;
|
|
14
|
+
addSchema(schema: Record<string, SchemaObject>): this;
|
|
15
|
+
addTag(name: string, description?: string, externalDocs?: ExternalDocumentationObject): this;
|
|
16
|
+
addSecurity(name: string, options: SecuritySchemeObject): this;
|
|
17
|
+
addSecurityRequirements(name: string | SecurityRequirementObject, requirements?: string[]): this;
|
|
18
|
+
addBearerAuth(options?: SecuritySchemeObject, name?: string): this;
|
|
19
|
+
addOAuth2(options?: SecuritySchemeObject, name?: string): this;
|
|
20
|
+
addApiKey(options?: SecuritySchemeObject, name?: string): this;
|
|
21
|
+
addBasicAuth(options?: SecuritySchemeObject, name?: string): this;
|
|
22
|
+
addCookieAuth(cookieName?: string, options?: SecuritySchemeObject, securityName?: string): this;
|
|
23
|
+
build(): Omit<OpenAPIObject, 'paths'>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=documentBuilder.d.ts.map
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentBuilder = void 0;
|
|
4
|
+
class DocumentBuilder {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.document = {
|
|
7
|
+
openapi: '3.0.1',
|
|
8
|
+
info: {
|
|
9
|
+
title: '',
|
|
10
|
+
description: '',
|
|
11
|
+
version: '1.0.0',
|
|
12
|
+
contact: {},
|
|
13
|
+
},
|
|
14
|
+
tags: [],
|
|
15
|
+
servers: [],
|
|
16
|
+
components: {},
|
|
17
|
+
paths: {},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
setTitle(title) {
|
|
21
|
+
this.document.info.title = title;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
setDescription(description) {
|
|
25
|
+
this.document.info.description = description;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
setVersion(version) {
|
|
29
|
+
this.document.info.version = version;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
setTermsOfService(termsOfService) {
|
|
33
|
+
this.document.info.termsOfService = termsOfService;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
setContact(name, url, email) {
|
|
37
|
+
this.document.info.contact = { name, url, email };
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
setLicense(name, url) {
|
|
41
|
+
this.document.info.license = { name, url };
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
addServer(url, description, variables) {
|
|
45
|
+
this.document.servers.push({ url, description, variables });
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
setExternalDoc(description, url) {
|
|
49
|
+
this.document.externalDocs = { description, url };
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
setBasePath(path) {
|
|
53
|
+
if (this.document.basePath) {
|
|
54
|
+
if (Array.isArray(this.document.basePath)) {
|
|
55
|
+
this.document.basePath.push(path);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.document.basePath = [
|
|
59
|
+
this.document.basePath,
|
|
60
|
+
path,
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.document.basePath = path;
|
|
66
|
+
}
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
addPaths(paths) {
|
|
70
|
+
Object.assign(this.document.paths, paths);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
addSchema(schema) {
|
|
74
|
+
if (!this.document.components.schemas) {
|
|
75
|
+
this.document.components.schemas = {};
|
|
76
|
+
}
|
|
77
|
+
Object.assign(this.document.components.schemas, schema);
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
addTag(name, description = '', externalDocs) {
|
|
81
|
+
if (Array.isArray(name)) {
|
|
82
|
+
const arr = name;
|
|
83
|
+
for (const s of arr) {
|
|
84
|
+
this.document.tags.push({
|
|
85
|
+
name: s,
|
|
86
|
+
description: '',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
this.document.tags.push({
|
|
92
|
+
name,
|
|
93
|
+
description,
|
|
94
|
+
externalDocs,
|
|
95
|
+
});
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
addSecurity(name, options) {
|
|
99
|
+
this.document.components.securitySchemes = {
|
|
100
|
+
...(this.document.components.securitySchemes || {}),
|
|
101
|
+
[name]: options,
|
|
102
|
+
};
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
addSecurityRequirements(name, requirements = []) {
|
|
106
|
+
let securityRequirement;
|
|
107
|
+
if (typeof name === 'string') {
|
|
108
|
+
securityRequirement = { [name]: requirements };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
securityRequirement = name;
|
|
112
|
+
}
|
|
113
|
+
this.document.security = (this.document.security || []).concat({
|
|
114
|
+
...securityRequirement,
|
|
115
|
+
});
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
addBearerAuth(options = {
|
|
119
|
+
type: 'http',
|
|
120
|
+
}, name = 'bearer') {
|
|
121
|
+
this.addSecurity(name, {
|
|
122
|
+
type: 'http',
|
|
123
|
+
scheme: 'bearer',
|
|
124
|
+
bearerFormat: 'JWT',
|
|
125
|
+
...options,
|
|
126
|
+
});
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
addOAuth2(options = {
|
|
130
|
+
type: 'oauth2',
|
|
131
|
+
}, name = 'oauth2') {
|
|
132
|
+
if (!name) {
|
|
133
|
+
name = 'oauth2';
|
|
134
|
+
}
|
|
135
|
+
this.addSecurity(name, {
|
|
136
|
+
type: 'oauth2',
|
|
137
|
+
flows: {
|
|
138
|
+
...options === null || options === void 0 ? void 0 : options.flows,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
addApiKey(options = {
|
|
144
|
+
type: 'apiKey',
|
|
145
|
+
}, name = 'api_key') {
|
|
146
|
+
if (!name) {
|
|
147
|
+
name = 'api_key';
|
|
148
|
+
}
|
|
149
|
+
this.addSecurity(name, {
|
|
150
|
+
type: 'apiKey',
|
|
151
|
+
in: 'header',
|
|
152
|
+
name,
|
|
153
|
+
...options,
|
|
154
|
+
});
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
addBasicAuth(options = {
|
|
158
|
+
type: 'http',
|
|
159
|
+
}, name = 'basic') {
|
|
160
|
+
if (!name) {
|
|
161
|
+
name = 'basic';
|
|
162
|
+
}
|
|
163
|
+
this.addSecurity(name, {
|
|
164
|
+
type: 'http',
|
|
165
|
+
scheme: 'basic',
|
|
166
|
+
...options,
|
|
167
|
+
});
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
addCookieAuth(cookieName = 'connect.sid', options = {
|
|
171
|
+
type: 'apiKey',
|
|
172
|
+
}, securityName = 'cookie') {
|
|
173
|
+
if (!cookieName) {
|
|
174
|
+
cookieName = 'connect.sid';
|
|
175
|
+
}
|
|
176
|
+
if (!securityName) {
|
|
177
|
+
securityName = 'cookie';
|
|
178
|
+
}
|
|
179
|
+
this.addSecurity(securityName, {
|
|
180
|
+
type: 'apiKey',
|
|
181
|
+
in: 'cookie',
|
|
182
|
+
name: cookieName,
|
|
183
|
+
...options,
|
|
184
|
+
});
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
build() {
|
|
188
|
+
return this.document;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.DocumentBuilder = DocumentBuilder;
|
|
192
|
+
//# sourceMappingURL=documentBuilder.js.map
|