@globalart/nestjs-swagger 1.2.5 → 1.2.6
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/dist/index.d.ts +41 -3
- package/dist/index.js +118 -18
- package/dist/index.js.map +1 -0
- package/package.json +11 -11
- package/dist/constants.d.ts +0 -12
- package/dist/constants.js +0 -15
- package/dist/decorators/index.d.ts +0 -2
- package/dist/decorators/index.js +0 -103
- package/dist/dtos/index.d.ts +0 -6
- package/dist/dtos/index.js +0 -32
- package/dist/interfaces/index.d.ts +0 -19
- package/dist/interfaces/index.js +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
declare const API_RESPONSE_DESCRIPTION = "If the server is available, it always responds with code 200 or 201. Error code 400 and higher will replace the ok field: it equals false and the error text in the error field. If the input data does not pass validation, the error field contains an object with invalid fields and error text";
|
|
3
|
+
declare const ERROR_DESCRIPTIONS: {
|
|
4
|
+
BAD_REQUEST: string;
|
|
5
|
+
UNAUTHORIZED: string;
|
|
6
|
+
FORBIDDEN: string;
|
|
7
|
+
NOT_FOUND: string;
|
|
8
|
+
CONFLICT: string;
|
|
9
|
+
UNPROCESSABLE_ENTITY: string;
|
|
10
|
+
RATE_LIMIT_EXCEEDED: string;
|
|
11
|
+
INTERNAL_SERVER_ERROR: string;
|
|
12
|
+
SERVICE_UNAVAILABLE: string;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/interfaces/index.d.ts
|
|
16
|
+
interface SwaggerDocumentationErrorStatus {
|
|
17
|
+
error400Description?: string;
|
|
18
|
+
error401Description?: string;
|
|
19
|
+
error403Description?: string;
|
|
20
|
+
error404Description?: string;
|
|
21
|
+
error409Description?: string;
|
|
22
|
+
error422Description?: string;
|
|
23
|
+
error429Description?: string;
|
|
24
|
+
error500Description?: string;
|
|
25
|
+
error503Description?: string;
|
|
26
|
+
}
|
|
27
|
+
interface SwaggerDocumentationOptions extends SwaggerDocumentationErrorStatus {
|
|
28
|
+
endpointSummary: string;
|
|
29
|
+
endpointDescription?: string;
|
|
30
|
+
operationId?: string;
|
|
31
|
+
responseDto?: any;
|
|
32
|
+
isArray?: boolean;
|
|
33
|
+
isPaginated?: boolean;
|
|
34
|
+
deprecated?: boolean;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/decorators/index.d.ts
|
|
38
|
+
declare const SwaggerDocumentation: (data: SwaggerDocumentationOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { API_RESPONSE_DESCRIPTION, ERROR_DESCRIPTIONS, SwaggerDocumentation, SwaggerDocumentationErrorStatus, SwaggerDocumentationOptions };
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1
|
+
import { applyDecorators } from "@nestjs/common";
|
|
2
|
+
import { ApiBadRequestResponse, ApiConflictResponse, ApiExtraModels, ApiForbiddenResponse, ApiInternalServerErrorResponse, ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiProperty, ApiServiceUnavailableResponse, ApiTooManyRequestsResponse, ApiUnauthorizedResponse, ApiUnprocessableEntityResponse, getSchemaPath } from "@nestjs/swagger";
|
|
3
|
+
import { createHash } from "crypto";
|
|
4
|
+
|
|
5
|
+
//#region rolldown:runtime
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __commonJS = (cb, mod) => function() {
|
|
13
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
17
|
+
key = keys[i];
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: ((k) => from[k]).bind(null, key),
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/constants.ts
|
|
32
|
+
const API_RESPONSE_DESCRIPTION = "If the server is available, it always responds with code 200 or 201. Error code 400 and higher will replace the ok field: it equals false and the error text in the error field. If the input data does not pass validation, the error field contains an object with invalid fields and error text";
|
|
33
|
+
const ERROR_DESCRIPTIONS = {
|
|
34
|
+
BAD_REQUEST: "Invalid request data or parameters",
|
|
35
|
+
UNAUTHORIZED: "Authentication required",
|
|
36
|
+
FORBIDDEN: "Access denied",
|
|
37
|
+
NOT_FOUND: "Resource not found",
|
|
38
|
+
CONFLICT: "Resource already exists or conflict detected",
|
|
39
|
+
UNPROCESSABLE_ENTITY: "Validation error",
|
|
40
|
+
RATE_LIMIT_EXCEEDED: "Rate limit exceeded. Too many requests",
|
|
41
|
+
INTERNAL_SERVER_ERROR: "Internal server error",
|
|
42
|
+
SERVICE_UNAVAILABLE: "Service temporarily unavailable"
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.87.0/node_modules/@oxc-project/runtime/src/helpers/decorateMetadata.js
|
|
47
|
+
var require_decorateMetadata = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.87.0/node_modules/@oxc-project/runtime/src/helpers/decorateMetadata.js": ((exports, module) => {
|
|
48
|
+
function __decorateMetadata(k, v) {
|
|
49
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
50
|
+
}
|
|
51
|
+
module.exports = __decorateMetadata, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
52
|
+
}) });
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.87.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
56
|
+
var require_decorate = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.87.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js": ((exports, module) => {
|
|
57
|
+
function __decorate(decorators, target, key, desc) {
|
|
58
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
59
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
60
|
+
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;
|
|
61
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
62
|
+
}
|
|
63
|
+
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
64
|
+
}) });
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/dtos/index.ts
|
|
68
|
+
var import_decorateMetadata = /* @__PURE__ */ __toESM(require_decorateMetadata(), 1);
|
|
69
|
+
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
70
|
+
var PaginatedResponseDto = class {
|
|
71
|
+
data;
|
|
72
|
+
totalCount;
|
|
73
|
+
offset;
|
|
74
|
+
limit;
|
|
75
|
+
};
|
|
76
|
+
(0, import_decorate.default)([ApiProperty(), (0, import_decorateMetadata.default)("design:type", Number)], PaginatedResponseDto.prototype, "totalCount", void 0);
|
|
77
|
+
(0, import_decorate.default)([ApiProperty(), (0, import_decorateMetadata.default)("design:type", Number)], PaginatedResponseDto.prototype, "offset", void 0);
|
|
78
|
+
(0, import_decorate.default)([ApiProperty(), (0, import_decorateMetadata.default)("design:type", Number)], PaginatedResponseDto.prototype, "limit", void 0);
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/decorators/index.ts
|
|
82
|
+
const SwaggerDocumentation = (data) => {
|
|
83
|
+
const operationId = data.operationId || createHash("md5").update(`${data.endpointSummary}`).digest("hex");
|
|
84
|
+
const decorators = [ApiOperation({
|
|
85
|
+
operationId,
|
|
86
|
+
description: data.endpointDescription,
|
|
87
|
+
summary: data.endpointSummary,
|
|
88
|
+
deprecated: data.deprecated
|
|
89
|
+
})];
|
|
90
|
+
if (data.error400Description) decorators.push(ApiBadRequestResponse({ description: data.error400Description }));
|
|
91
|
+
if (data.error401Description) decorators.push(ApiUnauthorizedResponse({ description: data.error401Description }));
|
|
92
|
+
if (data.error403Description) decorators.push(ApiForbiddenResponse({ description: data.error403Description }));
|
|
93
|
+
if (data.error404Description) decorators.push(ApiNotFoundResponse({ description: data.error404Description }));
|
|
94
|
+
if (data.error409Description) decorators.push(ApiConflictResponse({ description: data.error409Description }));
|
|
95
|
+
if (data.error422Description) decorators.push(ApiUnprocessableEntityResponse({ description: data.error422Description }));
|
|
96
|
+
if (data.error429Description) decorators.push(ApiTooManyRequestsResponse({ description: data.error429Description }));
|
|
97
|
+
if (data.error500Description) decorators.push(ApiInternalServerErrorResponse({ description: data.error500Description }));
|
|
98
|
+
if (data.error503Description) decorators.push(ApiServiceUnavailableResponse({ description: data.error503Description }));
|
|
99
|
+
if (data.isPaginated && data.responseDto) decorators.push(ApiOkResponse({
|
|
100
|
+
schema: { allOf: [{ $ref: getSchemaPath(PaginatedResponseDto) }, { properties: { data: {
|
|
101
|
+
type: "array",
|
|
102
|
+
items: { $ref: getSchemaPath(data.responseDto) }
|
|
103
|
+
} } }] },
|
|
104
|
+
description: API_RESPONSE_DESCRIPTION
|
|
105
|
+
}), ApiExtraModels(data.responseDto, PaginatedResponseDto));
|
|
106
|
+
else if (data.responseDto) decorators.push(ApiOkResponse({
|
|
107
|
+
schema: data.isArray ? {
|
|
108
|
+
type: "array",
|
|
109
|
+
items: { $ref: getSchemaPath(data.responseDto) }
|
|
110
|
+
} : { $ref: getSchemaPath(data.responseDto) },
|
|
111
|
+
description: API_RESPONSE_DESCRIPTION
|
|
112
|
+
}), ApiExtraModels(data.responseDto));
|
|
113
|
+
else decorators.push(ApiOkResponse({ description: API_RESPONSE_DESCRIPTION }));
|
|
114
|
+
return applyDecorators(...decorators);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { API_RESPONSE_DESCRIPTION, ERROR_DESCRIPTIONS, SwaggerDocumentation };
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/constants.ts","../../../node_modules/.pnpm/@oxc-project+runtime@0.87.0/node_modules/@oxc-project/runtime/src/helpers/decorateMetadata.js","../../../node_modules/.pnpm/@oxc-project+runtime@0.87.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js","../src/dtos/index.ts","../src/decorators/index.ts"],"sourcesContent":["export const API_RESPONSE_DESCRIPTION =\n \"If the server is available, it always responds with code 200 or 201. Error code 400 and higher will replace the ok field: it equals false and the error text in the error field. If the input data does not pass validation, the error field contains an object with invalid fields and error text\";\n\nexport const ERROR_DESCRIPTIONS = {\n BAD_REQUEST: \"Invalid request data or parameters\",\n UNAUTHORIZED: \"Authentication required\",\n FORBIDDEN: \"Access denied\",\n NOT_FOUND: \"Resource not found\",\n CONFLICT: \"Resource already exists or conflict detected\",\n UNPROCESSABLE_ENTITY: \"Validation error\",\n RATE_LIMIT_EXCEEDED: \"Rate limit exceeded. Too many requests\",\n INTERNAL_SERVER_ERROR: \"Internal server error\",\n SERVICE_UNAVAILABLE: \"Service temporarily unavailable\",\n};\n","// Copy from https://github.com/microsoft/TypeScript/blob/d85767abfd83880cea17cea70f9913e9c4496dcc/src/compiler/factory/emitHelpers.ts#L744-L753\n\nfunction __decorateMetadata(k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\n\n(module.exports = __decorateMetadata),\n (module.exports.__esModule = true),\n (module.exports[\"default\"] = module.exports);\n","// Copy from https://github.com/microsoft/TypeScript/blob/d85767abfd83880cea17cea70f9913e9c4496dcc/src/compiler/factory/emitHelpers.ts#L730-L742\n\nfunction __decorate(decorators, target, key, desc) {\n var c = arguments.length,\n r =\n c < 3\n ? target\n : desc === null\n ? (desc = Object.getOwnPropertyDescriptor(target, key))\n : desc,\n d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\")\n r = Reflect.decorate(decorators, target, key, desc);\n else\n for (var i = decorators.length - 1; i >= 0; i--)\n if ((d = decorators[i]))\n r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\n(module.exports = __decorate),\n (module.exports.__esModule = true),\n (module.exports[\"default\"] = module.exports);\n","import { ApiProperty } from \"@nestjs/swagger\";\n\nexport class PaginatedResponseDto<T> {\n data!: T[];\n\n @ApiProperty()\n totalCount!: number;\n\n @ApiProperty()\n offset!: number;\n\n @ApiProperty()\n limit!: number;\n}\n","import { applyDecorators } from \"@nestjs/common\";\nimport {\n ApiBadRequestResponse,\n ApiConflictResponse,\n ApiExtraModels,\n ApiForbiddenResponse,\n ApiInternalServerErrorResponse,\n ApiNotFoundResponse,\n ApiOkResponse,\n ApiOperation,\n ApiServiceUnavailableResponse,\n ApiTooManyRequestsResponse,\n ApiUnauthorizedResponse,\n ApiUnprocessableEntityResponse,\n getSchemaPath,\n} from \"@nestjs/swagger\";\nimport { API_RESPONSE_DESCRIPTION } from \"../constants\";\nimport { PaginatedResponseDto } from \"../dtos\";\nimport { SwaggerDocumentationOptions } from \"../interfaces\";\nimport { createHash } from \"crypto\";\n\n// SwaggerDocumentation is a decorator function to generate Swagger documentation for endpoints based on the provided options.\nexport const SwaggerDocumentation = (data: SwaggerDocumentationOptions) => {\n const operationId =\n data.operationId ||\n createHash(\"md5\").update(`${data.endpointSummary}`).digest(\"hex\");\n\n const decorators = [\n ApiOperation({\n operationId,\n description: data.endpointDescription,\n summary: data.endpointSummary,\n deprecated: data.deprecated,\n }),\n ];\n\n if (data.error400Description) {\n decorators.push(\n ApiBadRequestResponse({\n description: data.error400Description,\n })\n );\n }\n\n if (data.error401Description) {\n decorators.push(\n ApiUnauthorizedResponse({\n description: data.error401Description,\n })\n );\n }\n\n if (data.error403Description) {\n decorators.push(\n ApiForbiddenResponse({\n description: data.error403Description,\n })\n );\n }\n\n if (data.error404Description) {\n decorators.push(\n ApiNotFoundResponse({\n description: data.error404Description,\n })\n );\n }\n\n if (data.error409Description) {\n decorators.push(\n ApiConflictResponse({\n description: data.error409Description,\n })\n );\n }\n\n if (data.error422Description) {\n decorators.push(\n ApiUnprocessableEntityResponse({\n description: data.error422Description,\n })\n );\n }\n\n if (data.error429Description) {\n decorators.push(\n ApiTooManyRequestsResponse({\n description: data.error429Description,\n })\n );\n }\n\n if (data.error500Description) {\n decorators.push(\n ApiInternalServerErrorResponse({\n description: data.error500Description,\n })\n );\n }\n\n if (data.error503Description) {\n decorators.push(\n ApiServiceUnavailableResponse({\n description: data.error503Description,\n })\n );\n }\n\n if (data.isPaginated && data.responseDto) {\n decorators.push(\n ApiOkResponse({\n schema: {\n allOf: [\n { $ref: getSchemaPath(PaginatedResponseDto) },\n {\n properties: {\n data: {\n type: \"array\",\n items: {\n $ref: getSchemaPath(data.responseDto),\n },\n },\n },\n },\n ],\n },\n description: API_RESPONSE_DESCRIPTION,\n }),\n ApiExtraModels(data.responseDto, PaginatedResponseDto)\n );\n } else if (data.responseDto) {\n decorators.push(\n ApiOkResponse({\n schema: data.isArray\n ? {\n type: \"array\",\n items: { $ref: getSchemaPath(data.responseDto) },\n }\n : { $ref: getSchemaPath(data.responseDto) },\n description: API_RESPONSE_DESCRIPTION,\n }),\n ApiExtraModels(data.responseDto)\n );\n } else {\n decorators.push(\n ApiOkResponse({\n description: API_RESPONSE_DESCRIPTION,\n })\n );\n }\n\n return applyDecorators(...decorators);\n};\n"],"x_google_ignoreList":[1,2],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalart/nestjs-swagger",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "A simple documentation builder for NestJS Swagger Module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "GlobalArt, Inc"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
11
10
|
"files": [
|
|
12
11
|
"dist",
|
|
13
12
|
"README.md",
|
|
14
13
|
"LICENSE"
|
|
15
14
|
],
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
16
18
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
|
|
19
|
-
"import": "./dist/index.js",
|
|
20
|
-
"types": "./dist/index.d.ts"
|
|
21
|
-
}
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./package.json": "./package.json"
|
|
22
21
|
},
|
|
23
22
|
"repository": {
|
|
24
23
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/GlobalArtInc/
|
|
24
|
+
"url": "git+https://github.com/GlobalArtInc/ecosystem.git#main"
|
|
26
25
|
},
|
|
27
26
|
"keywords": [
|
|
28
27
|
"nestjs",
|
|
@@ -34,8 +33,8 @@
|
|
|
34
33
|
"test": "jest --runInBand --passWithNoTests",
|
|
35
34
|
"test:cov": "jest --coverage --passWithNoTests",
|
|
36
35
|
"coveralls": "yarn run test:cov --coverageReporters=text-lcov | coveralls",
|
|
37
|
-
"build": "
|
|
38
|
-
"build:watch": "
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"build:watch": "tsdown --watch",
|
|
39
38
|
"prepublishOnly": "npm run build",
|
|
40
39
|
"publish:dev": "npm publish --access public --tag dev",
|
|
41
40
|
"publish:npm": "release-it"
|
|
@@ -60,6 +59,7 @@
|
|
|
60
59
|
"ts-jest": "^29.4.0",
|
|
61
60
|
"ts-node": "^10.9.2",
|
|
62
61
|
"typeorm": "0.3.26",
|
|
62
|
+
"tsdown": "0.15.7",
|
|
63
63
|
"typescript": "^5.9.2"
|
|
64
64
|
},
|
|
65
65
|
"jest": {
|
package/dist/constants.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const API_RESPONSE_DESCRIPTION = "If the server is available, it always responds with code 200 or 201. Error code 400 and higher will replace the ok field: it equals false and the error text in the error field. If the input data does not pass validation, the error field contains an object with invalid fields and error text";
|
|
2
|
-
export declare const ERROR_DESCRIPTIONS: {
|
|
3
|
-
BAD_REQUEST: string;
|
|
4
|
-
UNAUTHORIZED: string;
|
|
5
|
-
FORBIDDEN: string;
|
|
6
|
-
NOT_FOUND: string;
|
|
7
|
-
CONFLICT: string;
|
|
8
|
-
UNPROCESSABLE_ENTITY: string;
|
|
9
|
-
RATE_LIMIT_EXCEEDED: string;
|
|
10
|
-
INTERNAL_SERVER_ERROR: string;
|
|
11
|
-
SERVICE_UNAVAILABLE: string;
|
|
12
|
-
};
|
package/dist/constants.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ERROR_DESCRIPTIONS = exports.API_RESPONSE_DESCRIPTION = void 0;
|
|
4
|
-
exports.API_RESPONSE_DESCRIPTION = "If the server is available, it always responds with code 200 or 201. Error code 400 and higher will replace the ok field: it equals false and the error text in the error field. If the input data does not pass validation, the error field contains an object with invalid fields and error text";
|
|
5
|
-
exports.ERROR_DESCRIPTIONS = {
|
|
6
|
-
BAD_REQUEST: "Invalid request data or parameters",
|
|
7
|
-
UNAUTHORIZED: "Authentication required",
|
|
8
|
-
FORBIDDEN: "Access denied",
|
|
9
|
-
NOT_FOUND: "Resource not found",
|
|
10
|
-
CONFLICT: "Resource already exists or conflict detected",
|
|
11
|
-
UNPROCESSABLE_ENTITY: "Validation error",
|
|
12
|
-
RATE_LIMIT_EXCEEDED: "Rate limit exceeded. Too many requests",
|
|
13
|
-
INTERNAL_SERVER_ERROR: "Internal server error",
|
|
14
|
-
SERVICE_UNAVAILABLE: "Service temporarily unavailable",
|
|
15
|
-
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { SwaggerDocumentationOptions } from "../interfaces";
|
|
2
|
-
export declare const SwaggerDocumentation: (data: SwaggerDocumentationOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
package/dist/decorators/index.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SwaggerDocumentation = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
const dtos_1 = require("../dtos");
|
|
8
|
-
const crypto_1 = require("crypto");
|
|
9
|
-
// SwaggerDocumentation is a decorator function to generate Swagger documentation for endpoints based on the provided options.
|
|
10
|
-
const SwaggerDocumentation = (data) => {
|
|
11
|
-
const operationId = data.operationId ||
|
|
12
|
-
(0, crypto_1.createHash)("md5").update(`${data.endpointSummary}`).digest("hex");
|
|
13
|
-
const decorators = [
|
|
14
|
-
(0, swagger_1.ApiOperation)({
|
|
15
|
-
operationId,
|
|
16
|
-
description: data.endpointDescription,
|
|
17
|
-
summary: data.endpointSummary,
|
|
18
|
-
}),
|
|
19
|
-
];
|
|
20
|
-
if (data.error400Description) {
|
|
21
|
-
decorators.push((0, swagger_1.ApiBadRequestResponse)({
|
|
22
|
-
description: data.error400Description,
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
if (data.error401Description) {
|
|
26
|
-
decorators.push((0, swagger_1.ApiUnauthorizedResponse)({
|
|
27
|
-
description: data.error401Description,
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
if (data.error403Description) {
|
|
31
|
-
decorators.push((0, swagger_1.ApiForbiddenResponse)({
|
|
32
|
-
description: data.error403Description,
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
if (data.error404Description) {
|
|
36
|
-
decorators.push((0, swagger_1.ApiNotFoundResponse)({
|
|
37
|
-
description: data.error404Description,
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
if (data.error409Description) {
|
|
41
|
-
decorators.push((0, swagger_1.ApiConflictResponse)({
|
|
42
|
-
description: data.error409Description,
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
if (data.error422Description) {
|
|
46
|
-
decorators.push((0, swagger_1.ApiUnprocessableEntityResponse)({
|
|
47
|
-
description: data.error422Description,
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
if (data.error429Description) {
|
|
51
|
-
decorators.push((0, swagger_1.ApiTooManyRequestsResponse)({
|
|
52
|
-
description: data.error429Description,
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
if (data.error500Description) {
|
|
56
|
-
decorators.push((0, swagger_1.ApiInternalServerErrorResponse)({
|
|
57
|
-
description: data.error500Description,
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
if (data.error503Description) {
|
|
61
|
-
decorators.push((0, swagger_1.ApiServiceUnavailableResponse)({
|
|
62
|
-
description: data.error503Description,
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
if (data.isPaginated && data.responseDto) {
|
|
66
|
-
decorators.push((0, swagger_1.ApiOkResponse)({
|
|
67
|
-
schema: {
|
|
68
|
-
allOf: [
|
|
69
|
-
{ $ref: (0, swagger_1.getSchemaPath)(dtos_1.PaginatedResponseDto) },
|
|
70
|
-
{
|
|
71
|
-
properties: {
|
|
72
|
-
data: {
|
|
73
|
-
type: "array",
|
|
74
|
-
items: {
|
|
75
|
-
$ref: (0, swagger_1.getSchemaPath)(data.responseDto),
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
description: constants_1.API_RESPONSE_DESCRIPTION,
|
|
83
|
-
}), (0, swagger_1.ApiExtraModels)(data.responseDto, dtos_1.PaginatedResponseDto));
|
|
84
|
-
}
|
|
85
|
-
else if (data.responseDto) {
|
|
86
|
-
decorators.push((0, swagger_1.ApiOkResponse)({
|
|
87
|
-
schema: data.isArray
|
|
88
|
-
? {
|
|
89
|
-
type: "array",
|
|
90
|
-
items: { $ref: (0, swagger_1.getSchemaPath)(data.responseDto) },
|
|
91
|
-
}
|
|
92
|
-
: { $ref: (0, swagger_1.getSchemaPath)(data.responseDto) },
|
|
93
|
-
description: constants_1.API_RESPONSE_DESCRIPTION,
|
|
94
|
-
}), (0, swagger_1.ApiExtraModels)(data.responseDto));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
decorators.push((0, swagger_1.ApiOkResponse)({
|
|
98
|
-
description: constants_1.API_RESPONSE_DESCRIPTION,
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
return (0, common_1.applyDecorators)(...decorators);
|
|
102
|
-
};
|
|
103
|
-
exports.SwaggerDocumentation = SwaggerDocumentation;
|
package/dist/dtos/index.d.ts
DELETED
package/dist/dtos/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.PaginatedResponseDto = void 0;
|
|
13
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
-
class PaginatedResponseDto {
|
|
15
|
-
data;
|
|
16
|
-
totalCount;
|
|
17
|
-
offset;
|
|
18
|
-
limit;
|
|
19
|
-
}
|
|
20
|
-
exports.PaginatedResponseDto = PaginatedResponseDto;
|
|
21
|
-
__decorate([
|
|
22
|
-
(0, swagger_1.ApiProperty)(),
|
|
23
|
-
__metadata("design:type", Number)
|
|
24
|
-
], PaginatedResponseDto.prototype, "totalCount", void 0);
|
|
25
|
-
__decorate([
|
|
26
|
-
(0, swagger_1.ApiProperty)(),
|
|
27
|
-
__metadata("design:type", Number)
|
|
28
|
-
], PaginatedResponseDto.prototype, "offset", void 0);
|
|
29
|
-
__decorate([
|
|
30
|
-
(0, swagger_1.ApiProperty)(),
|
|
31
|
-
__metadata("design:type", Number)
|
|
32
|
-
], PaginatedResponseDto.prototype, "limit", void 0);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface SwaggerDocumentationErrorStatus {
|
|
2
|
-
error400Description?: string;
|
|
3
|
-
error401Description?: string;
|
|
4
|
-
error403Description?: string;
|
|
5
|
-
error404Description?: string;
|
|
6
|
-
error409Description?: string;
|
|
7
|
-
error422Description?: string;
|
|
8
|
-
error429Description?: string;
|
|
9
|
-
error500Description?: string;
|
|
10
|
-
error503Description?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface SwaggerDocumentationOptions extends SwaggerDocumentationErrorStatus {
|
|
13
|
-
endpointSummary: string;
|
|
14
|
-
endpointDescription?: string;
|
|
15
|
-
operationId?: string;
|
|
16
|
-
responseDto?: any;
|
|
17
|
-
isArray?: boolean;
|
|
18
|
-
isPaginated?: boolean;
|
|
19
|
-
}
|
package/dist/interfaces/index.js
DELETED