@globalart/nestjs-swagger 1.2.6 → 1.2.7
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 +4 -197
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +1 -1
- package/dist/index.d.mts +41 -0
- package/dist/{index.js → index.mjs} +16 -51
- package/dist/index.mjs.map +1 -0
- package/package.json +27 -19
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,203 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A simple documentation builder for NestJS Swagger module that simplifies creating OpenAPI documentation for your REST APIs.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Documentation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm install @globalart/nestjs-swagger
|
|
9
|
-
```
|
|
7
|
+
For complete documentation, examples, and API reference, please visit the [official documentation](https://globalart.js.org/packages/nestjs-swagger).
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
## License
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
yarn add @globalart/nestjs-swagger
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Description
|
|
18
|
-
|
|
19
|
-
This package provides a convenient `SwaggerDocumentation` decorator for automatic Swagger documentation generation in NestJS applications. It significantly simplifies the process of adding documentation to your endpoints by providing a unified interface for describing operations and possible errors.
|
|
20
|
-
|
|
21
|
-
## Key Features
|
|
22
|
-
|
|
23
|
-
- 📝 Simple decorator for endpoint documentation
|
|
24
|
-
- 🔧 Pre-configured descriptions for standard HTTP errors
|
|
25
|
-
- 📊 Support for paginated responses
|
|
26
|
-
- 🎯 Support for arrays in responses
|
|
27
|
-
- 📋 Automatic schema generation for DTOs
|
|
28
|
-
- 🛡️ Full TypeScript typing
|
|
29
|
-
|
|
30
|
-
## Quick Start
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { Controller, Get } from '@nestjs/common';
|
|
34
|
-
import { SwaggerDocumentation, ERROR_DESCRIPTIONS } from '@globalart/nestjs-swagger';
|
|
35
|
-
|
|
36
|
-
@Controller('users')
|
|
37
|
-
export class UsersController {
|
|
38
|
-
@Get()
|
|
39
|
-
@SwaggerDocumentation({
|
|
40
|
-
endpointDescription: 'Get list of all users',
|
|
41
|
-
endpointSummary: 'List users',
|
|
42
|
-
error400Description: ERROR_DESCRIPTIONS.BAD_REQUEST,
|
|
43
|
-
error401Description: ERROR_DESCRIPTIONS.UNAUTHORIZED,
|
|
44
|
-
error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
|
|
45
|
-
})
|
|
46
|
-
async getAllUsers() {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## API Reference
|
|
53
|
-
|
|
54
|
-
### SwaggerDocumentation
|
|
55
|
-
|
|
56
|
-
Decorator for automatic Swagger documentation generation.
|
|
57
|
-
|
|
58
|
-
#### Parameters
|
|
59
|
-
|
|
60
|
-
| Parameter | Type | Description |
|
|
61
|
-
| --------------------- | ---------- | ------------------------------------ |
|
|
62
|
-
| `endpointDescription` | `string` | Detailed endpoint description |
|
|
63
|
-
| `endpointSummary` | `string` | Brief endpoint description |
|
|
64
|
-
| `responseDto` | `Function` | DTO class for response |
|
|
65
|
-
| `isArray` | `boolean` | Indicates that response is an array |
|
|
66
|
-
| `isPaginated` | `boolean` | Indicates that response is paginated |
|
|
67
|
-
| `error400Description` | `string` | 400 error description |
|
|
68
|
-
| `error401Description` | `string` | 401 error description |
|
|
69
|
-
| `error403Description` | `string` | 403 error description |
|
|
70
|
-
| `error404Description` | `string` | 404 error description |
|
|
71
|
-
| `error409Description` | `string` | 409 error description |
|
|
72
|
-
| `error422Description` | `string` | 422 error description |
|
|
73
|
-
| `error429Description` | `string` | 429 error description |
|
|
74
|
-
| `error500Description` | `string` | 500 error description |
|
|
75
|
-
| `error503Description` | `string` | 503 error description |
|
|
76
|
-
|
|
77
|
-
### ERROR_DESCRIPTIONS
|
|
78
|
-
|
|
79
|
-
Object with pre-configured error descriptions:
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
export const ERROR_DESCRIPTIONS = {
|
|
83
|
-
BAD_REQUEST: "Invalid request data or parameters",
|
|
84
|
-
UNAUTHORIZED: "Authentication required",
|
|
85
|
-
FORBIDDEN: "Access denied",
|
|
86
|
-
NOT_FOUND: "Resource not found",
|
|
87
|
-
CONFLICT: "Resource already exists or conflict detected",
|
|
88
|
-
UNPROCESSABLE_ENTITY: "Validation error",
|
|
89
|
-
RATE_LIMIT_EXCEEDED: "Rate limit exceeded. Too many requests",
|
|
90
|
-
INTERNAL_SERVER_ERROR: "Internal server error",
|
|
91
|
-
SERVICE_UNAVAILABLE: "Service temporarily unavailable"
|
|
92
|
-
};
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Usage Examples
|
|
96
|
-
|
|
97
|
-
### Basic Usage
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { Controller, Get } from '@nestjs/common';
|
|
101
|
-
import { SwaggerDocumentation, ERROR_DESCRIPTIONS } from '@globalart/nestjs-swagger';
|
|
102
|
-
|
|
103
|
-
@Controller()
|
|
104
|
-
export class AppController {
|
|
105
|
-
@Get('hello')
|
|
106
|
-
@SwaggerDocumentation({
|
|
107
|
-
endpointDescription: 'Simple greeting endpoint',
|
|
108
|
-
endpointSummary: 'Greeting',
|
|
109
|
-
error400Description: ERROR_DESCRIPTIONS.BAD_REQUEST,
|
|
110
|
-
error401Description: ERROR_DESCRIPTIONS.UNAUTHORIZED,
|
|
111
|
-
error403Description: ERROR_DESCRIPTIONS.FORBIDDEN,
|
|
112
|
-
error404Description: ERROR_DESCRIPTIONS.NOT_FOUND,
|
|
113
|
-
error429Description: ERROR_DESCRIPTIONS.RATE_LIMIT_EXCEEDED,
|
|
114
|
-
error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
|
|
115
|
-
})
|
|
116
|
-
async hello() {
|
|
117
|
-
return 'Hello World';
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Using with DTO
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
126
|
-
|
|
127
|
-
export class UserDto {
|
|
128
|
-
@ApiProperty()
|
|
129
|
-
id: number;
|
|
130
|
-
|
|
131
|
-
@ApiProperty()
|
|
132
|
-
name: string;
|
|
133
|
-
|
|
134
|
-
@ApiProperty()
|
|
135
|
-
email: string;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
@Controller('users')
|
|
139
|
-
export class UsersController {
|
|
140
|
-
@Get(':id')
|
|
141
|
-
@SwaggerDocumentation({
|
|
142
|
-
endpointDescription: 'Get user by ID',
|
|
143
|
-
endpointSummary: 'Get user',
|
|
144
|
-
responseDto: UserDto,
|
|
145
|
-
error404Description: ERROR_DESCRIPTIONS.NOT_FOUND,
|
|
146
|
-
error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
|
|
147
|
-
})
|
|
148
|
-
async getUserById(@Param('id') id: number) {
|
|
149
|
-
// user retrieval logic
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Working with Arrays
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
@Controller('users')
|
|
158
|
-
export class UsersController {
|
|
159
|
-
@Get()
|
|
160
|
-
@SwaggerDocumentation({
|
|
161
|
-
endpointDescription: 'Get list of all users',
|
|
162
|
-
endpointSummary: 'List users',
|
|
163
|
-
responseDto: UserDto,
|
|
164
|
-
isArray: true,
|
|
165
|
-
error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
|
|
166
|
-
})
|
|
167
|
-
async getAllUsers() {
|
|
168
|
-
// user list retrieval logic
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Paginated Responses
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
@Controller('users')
|
|
177
|
-
export class UsersController {
|
|
178
|
-
@Get()
|
|
179
|
-
@SwaggerDocumentation({
|
|
180
|
-
endpointDescription: 'Get paginated list of users',
|
|
181
|
-
endpointSummary: 'Paginated user list',
|
|
182
|
-
responseDto: UserDto,
|
|
183
|
-
isPaginated: true,
|
|
184
|
-
error400Description: ERROR_DESCRIPTIONS.BAD_REQUEST,
|
|
185
|
-
error500Description: ERROR_DESCRIPTIONS.INTERNAL_SERVER_ERROR
|
|
186
|
-
})
|
|
187
|
-
async getPaginatedUsers(@Query() query: PaginationDto) {
|
|
188
|
-
// pagination logic
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Paginated Response Structure
|
|
194
|
-
|
|
195
|
-
When using `isPaginated: true`, the response is automatically wrapped in the structure:
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
{
|
|
199
|
-
data: T[], // array of objects of the specified DTO
|
|
200
|
-
totalCount: number, // total number of records
|
|
201
|
-
offset: number, // offset
|
|
202
|
-
limit: number // limit of records per page
|
|
203
|
-
}
|
|
204
|
-
```
|
|
11
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
let _nestjs_common = require("@nestjs/common");
|
|
2
|
+
let _nestjs_swagger = require("@nestjs/swagger");
|
|
3
|
+
|
|
4
|
+
//#region src/constants.ts
|
|
5
|
+
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";
|
|
6
|
+
const ERROR_DESCRIPTIONS = {
|
|
7
|
+
BAD_REQUEST: "Invalid request data or parameters",
|
|
8
|
+
UNAUTHORIZED: "Authentication required",
|
|
9
|
+
FORBIDDEN: "Access denied",
|
|
10
|
+
NOT_FOUND: "Resource not found",
|
|
11
|
+
CONFLICT: "Resource already exists or conflict detected",
|
|
12
|
+
UNPROCESSABLE_ENTITY: "Validation error",
|
|
13
|
+
RATE_LIMIT_EXCEEDED: "Rate limit exceeded. Too many requests",
|
|
14
|
+
INTERNAL_SERVER_ERROR: "Internal server error",
|
|
15
|
+
SERVICE_UNAVAILABLE: "Service temporarily unavailable"
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/decorateMetadata.js
|
|
20
|
+
function __decorateMetadata(k, v) {
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/decorate.js
|
|
26
|
+
function __decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
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;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/dtos/index.ts
|
|
35
|
+
var PaginatedResponseDto = class {
|
|
36
|
+
data;
|
|
37
|
+
totalCount;
|
|
38
|
+
offset;
|
|
39
|
+
limit;
|
|
40
|
+
};
|
|
41
|
+
__decorate([(0, _nestjs_swagger.ApiProperty)(), __decorateMetadata("design:type", Number)], PaginatedResponseDto.prototype, "totalCount", void 0);
|
|
42
|
+
__decorate([(0, _nestjs_swagger.ApiProperty)(), __decorateMetadata("design:type", Number)], PaginatedResponseDto.prototype, "offset", void 0);
|
|
43
|
+
__decorate([(0, _nestjs_swagger.ApiProperty)(), __decorateMetadata("design:type", Number)], PaginatedResponseDto.prototype, "limit", void 0);
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/decorators/index.ts
|
|
47
|
+
const SwaggerDocumentation = (data) => {
|
|
48
|
+
const operationId = data.operationId;
|
|
49
|
+
const decorators = [(0, _nestjs_swagger.ApiOperation)({
|
|
50
|
+
operationId,
|
|
51
|
+
description: data.endpointDescription,
|
|
52
|
+
summary: data.endpointSummary,
|
|
53
|
+
deprecated: data.deprecated
|
|
54
|
+
})];
|
|
55
|
+
if (data.error400Description) decorators.push((0, _nestjs_swagger.ApiBadRequestResponse)({ description: data.error400Description }));
|
|
56
|
+
if (data.error401Description) decorators.push((0, _nestjs_swagger.ApiUnauthorizedResponse)({ description: data.error401Description }));
|
|
57
|
+
if (data.error403Description) decorators.push((0, _nestjs_swagger.ApiForbiddenResponse)({ description: data.error403Description }));
|
|
58
|
+
if (data.error404Description) decorators.push((0, _nestjs_swagger.ApiNotFoundResponse)({ description: data.error404Description }));
|
|
59
|
+
if (data.error409Description) decorators.push((0, _nestjs_swagger.ApiConflictResponse)({ description: data.error409Description }));
|
|
60
|
+
if (data.error422Description) decorators.push((0, _nestjs_swagger.ApiUnprocessableEntityResponse)({ description: data.error422Description }));
|
|
61
|
+
if (data.error429Description) decorators.push((0, _nestjs_swagger.ApiTooManyRequestsResponse)({ description: data.error429Description }));
|
|
62
|
+
if (data.error500Description) decorators.push((0, _nestjs_swagger.ApiInternalServerErrorResponse)({ description: data.error500Description }));
|
|
63
|
+
if (data.error503Description) decorators.push((0, _nestjs_swagger.ApiServiceUnavailableResponse)({ description: data.error503Description }));
|
|
64
|
+
if (data.isPaginated && data.responseDto) decorators.push((0, _nestjs_swagger.ApiOkResponse)({
|
|
65
|
+
schema: { allOf: [{ $ref: (0, _nestjs_swagger.getSchemaPath)(PaginatedResponseDto) }, { properties: { data: {
|
|
66
|
+
type: "array",
|
|
67
|
+
items: { $ref: (0, _nestjs_swagger.getSchemaPath)(data.responseDto) }
|
|
68
|
+
} } }] },
|
|
69
|
+
description: API_RESPONSE_DESCRIPTION
|
|
70
|
+
}), (0, _nestjs_swagger.ApiExtraModels)(data.responseDto, PaginatedResponseDto));
|
|
71
|
+
else if (data.responseDto) decorators.push((0, _nestjs_swagger.ApiOkResponse)({
|
|
72
|
+
schema: data.isArray ? {
|
|
73
|
+
type: "array",
|
|
74
|
+
items: { $ref: (0, _nestjs_swagger.getSchemaPath)(data.responseDto) }
|
|
75
|
+
} : { $ref: (0, _nestjs_swagger.getSchemaPath)(data.responseDto) },
|
|
76
|
+
description: API_RESPONSE_DESCRIPTION
|
|
77
|
+
}), (0, _nestjs_swagger.ApiExtraModels)(data.responseDto));
|
|
78
|
+
else decorators.push((0, _nestjs_swagger.ApiOkResponse)({ description: API_RESPONSE_DESCRIPTION }));
|
|
79
|
+
return (0, _nestjs_common.applyDecorators)(...decorators);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
exports.API_RESPONSE_DESCRIPTION = API_RESPONSE_DESCRIPTION;
|
|
84
|
+
exports.ERROR_DESCRIPTIONS = ERROR_DESCRIPTIONS;
|
|
85
|
+
exports.SwaggerDocumentation = SwaggerDocumentation;
|
|
86
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/constants.ts","../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","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 = data.operationId;\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"],"mappings":";;;;AAAA,MAAa,2BACX;AAEF,MAAa,qBAAqB;CAChC,aAAa;CACb,cAAc;CACd,WAAW;CACX,WAAW;CACX,UAAU;CACV,sBAAsB;CACtB,qBAAqB;CACrB,uBAAuB;CACvB,qBAAqB;CACtB;;;;;;;;;;;;;;;;;;;ACXD,IAAa,uBAAb,MAAqC;CACnC;CAEA,AACA;CAEA,AACA;CAEA,AACA;;8CAPc;8CAGA;8CAGA;;;;ACWhB,MAAa,wBAAwB,SAAsC;CACzE,MAAM,cAAc,KAAK;CAEzB,MAAM,aAAa,mCACJ;EACX;EACA,aAAa,KAAK;EAClB,SAAS,KAAK;EACd,YAAY,KAAK;EAClB,CAAC,CACH;AAED,KAAI,KAAK,oBACP,YAAW,gDACa,EACpB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,kDACe,EACtB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,+CACY,EACnB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,8CACW,EAClB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,8CACW,EAClB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,yDACsB,EAC7B,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,qDACkB,EACzB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,yDACsB,EAC7B,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,wDACqB,EAC5B,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,eAAe,KAAK,YAC3B,YAAW,wCACK;EACZ,QAAQ,EACN,OAAO,CACL,EAAE,yCAAoB,qBAAqB,EAAE,EAC7C,EACE,YAAY,EACV,MAAM;GACJ,MAAM;GACN,OAAO,EACL,yCAAoB,KAAK,YAAY,EACtC;GACF,EACF,EACF,CACF,EACF;EACD,aAAa;EACd,CAAC,sCACa,KAAK,aAAa,qBAAqB,CACvD;UACQ,KAAK,YACd,YAAW,wCACK;EACZ,QAAQ,KAAK,UACT;GACE,MAAM;GACN,OAAO,EAAE,yCAAoB,KAAK,YAAY,EAAE;GACjD,GACD,EAAE,yCAAoB,KAAK,YAAY,EAAE;EAC7C,aAAa;EACd,CAAC,sCACa,KAAK,YAAY,CACjC;KAED,YAAW,wCACK,EACZ,aAAa,0BACd,CAAC,CACH;AAGH,4CAAuB,GAAG,WAAW"}
|
|
@@ -38,4 +38,4 @@ interface SwaggerDocumentationOptions extends SwaggerDocumentationErrorStatus {
|
|
|
38
38
|
declare const SwaggerDocumentation: (data: SwaggerDocumentationOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
39
39
|
//#endregion
|
|
40
40
|
export { API_RESPONSE_DESCRIPTION, ERROR_DESCRIPTIONS, SwaggerDocumentation, SwaggerDocumentationErrorStatus, SwaggerDocumentationOptions };
|
|
41
|
-
//# sourceMappingURL=index.d.
|
|
41
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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.mts.map
|
|
@@ -1,33 +1,6 @@
|
|
|
1
1
|
import { applyDecorators } from "@nestjs/common";
|
|
2
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
3
|
|
|
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;
|
|
14
|
-
};
|
|
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
4
|
//#region src/constants.ts
|
|
32
5
|
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
6
|
const ERROR_DESCRIPTIONS = {
|
|
@@ -43,44 +16,36 @@ const ERROR_DESCRIPTIONS = {
|
|
|
43
16
|
};
|
|
44
17
|
|
|
45
18
|
//#endregion
|
|
46
|
-
//#region
|
|
47
|
-
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
module.exports = __decorateMetadata, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
52
|
-
}) });
|
|
19
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/decorateMetadata.js
|
|
20
|
+
function __decorateMetadata(k, v) {
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
+
}
|
|
53
23
|
|
|
54
24
|
//#endregion
|
|
55
|
-
//#region
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
64
|
-
}) });
|
|
25
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/decorate.js
|
|
26
|
+
function __decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
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;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
65
32
|
|
|
66
33
|
//#endregion
|
|
67
34
|
//#region src/dtos/index.ts
|
|
68
|
-
var import_decorateMetadata = /* @__PURE__ */ __toESM(require_decorateMetadata(), 1);
|
|
69
|
-
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
70
35
|
var PaginatedResponseDto = class {
|
|
71
36
|
data;
|
|
72
37
|
totalCount;
|
|
73
38
|
offset;
|
|
74
39
|
limit;
|
|
75
40
|
};
|
|
76
|
-
(
|
|
77
|
-
(
|
|
78
|
-
(
|
|
41
|
+
__decorate([ApiProperty(), __decorateMetadata("design:type", Number)], PaginatedResponseDto.prototype, "totalCount", void 0);
|
|
42
|
+
__decorate([ApiProperty(), __decorateMetadata("design:type", Number)], PaginatedResponseDto.prototype, "offset", void 0);
|
|
43
|
+
__decorate([ApiProperty(), __decorateMetadata("design:type", Number)], PaginatedResponseDto.prototype, "limit", void 0);
|
|
79
44
|
|
|
80
45
|
//#endregion
|
|
81
46
|
//#region src/decorators/index.ts
|
|
82
47
|
const SwaggerDocumentation = (data) => {
|
|
83
|
-
const operationId = data.operationId
|
|
48
|
+
const operationId = data.operationId;
|
|
84
49
|
const decorators = [ApiOperation({
|
|
85
50
|
operationId,
|
|
86
51
|
description: data.endpointDescription,
|
|
@@ -116,4 +81,4 @@ const SwaggerDocumentation = (data) => {
|
|
|
116
81
|
|
|
117
82
|
//#endregion
|
|
118
83
|
export { API_RESPONSE_DESCRIPTION, ERROR_DESCRIPTIONS, SwaggerDocumentation };
|
|
119
|
-
//# sourceMappingURL=index.
|
|
84
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/constants.ts","../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","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 = data.operationId;\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"],"mappings":";;;;AAAA,MAAa,2BACX;AAEF,MAAa,qBAAqB;CAChC,aAAa;CACb,cAAc;CACd,WAAW;CACX,WAAW;CACX,UAAU;CACV,sBAAsB;CACtB,qBAAqB;CACrB,uBAAuB;CACvB,qBAAqB;CACtB;;;;;;;;;;;;;;;;;;;ACXD,IAAa,uBAAb,MAAqC;CACnC;CAEA,AACA;CAEA,AACA;CAEA,AACA;;YAPC,aAAa;YAGb,aAAa;YAGb,aAAa;;;;ACWhB,MAAa,wBAAwB,SAAsC;CACzE,MAAM,cAAc,KAAK;CAEzB,MAAM,aAAa,CACjB,aAAa;EACX;EACA,aAAa,KAAK;EAClB,SAAS,KAAK;EACd,YAAY,KAAK;EAClB,CAAC,CACH;AAED,KAAI,KAAK,oBACP,YAAW,KACT,sBAAsB,EACpB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,wBAAwB,EACtB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,qBAAqB,EACnB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,oBAAoB,EAClB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,oBAAoB,EAClB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,+BAA+B,EAC7B,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,2BAA2B,EACzB,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,+BAA+B,EAC7B,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,oBACP,YAAW,KACT,8BAA8B,EAC5B,aAAa,KAAK,qBACnB,CAAC,CACH;AAGH,KAAI,KAAK,eAAe,KAAK,YAC3B,YAAW,KACT,cAAc;EACZ,QAAQ,EACN,OAAO,CACL,EAAE,MAAM,cAAc,qBAAqB,EAAE,EAC7C,EACE,YAAY,EACV,MAAM;GACJ,MAAM;GACN,OAAO,EACL,MAAM,cAAc,KAAK,YAAY,EACtC;GACF,EACF,EACF,CACF,EACF;EACD,aAAa;EACd,CAAC,EACF,eAAe,KAAK,aAAa,qBAAqB,CACvD;UACQ,KAAK,YACd,YAAW,KACT,cAAc;EACZ,QAAQ,KAAK,UACT;GACE,MAAM;GACN,OAAO,EAAE,MAAM,cAAc,KAAK,YAAY,EAAE;GACjD,GACD,EAAE,MAAM,cAAc,KAAK,YAAY,EAAE;EAC7C,aAAa;EACd,CAAC,EACF,eAAe,KAAK,YAAY,CACjC;KAED,YAAW,KACT,cAAc,EACZ,aAAa,0BACd,CAAC,CACH;AAGH,QAAO,gBAAgB,GAAG,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalart/nestjs-swagger",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "A simple documentation builder for NestJS Swagger Module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "GlobalArt, Inc"
|
|
@@ -12,12 +12,20 @@
|
|
|
12
12
|
"README.md",
|
|
13
13
|
"LICENSE"
|
|
14
14
|
],
|
|
15
|
-
"main": "./dist/index.
|
|
16
|
-
"module": "./dist/index.
|
|
17
|
-
"types": "./dist/index.d.
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
18
|
"exports": {
|
|
19
|
-
".":
|
|
20
|
-
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
21
29
|
},
|
|
22
30
|
"repository": {
|
|
23
31
|
"type": "git",
|
|
@@ -37,30 +45,30 @@
|
|
|
37
45
|
"build:watch": "tsdown --watch",
|
|
38
46
|
"prepublishOnly": "npm run build",
|
|
39
47
|
"publish:dev": "npm publish --access public --tag dev",
|
|
40
|
-
"publish:npm": "release-it"
|
|
48
|
+
"publish:npm": "release-it --config ../../.release-it.json"
|
|
41
49
|
},
|
|
42
50
|
"dependencies": {
|
|
43
|
-
"@nestjs/common": "
|
|
44
|
-
"@nestjs/core": "
|
|
45
|
-
"@nestjs/swagger": "^11.2.
|
|
46
|
-
"@nestjs/testing": "
|
|
51
|
+
"@nestjs/common": "11.1.11",
|
|
52
|
+
"@nestjs/core": "11.1.11",
|
|
53
|
+
"@nestjs/swagger": "^11.2.3",
|
|
54
|
+
"@nestjs/testing": "11.1.11",
|
|
47
55
|
"@nestjs/typeorm": "^11.0.0",
|
|
48
56
|
"mysql": "^2.18.1"
|
|
49
57
|
},
|
|
50
58
|
"devDependencies": {
|
|
51
59
|
"@types/jest": "^30.0.0",
|
|
52
|
-
"@types/node": "
|
|
60
|
+
"@types/node": "25.0.3",
|
|
53
61
|
"coveralls": "^3.1.1",
|
|
54
|
-
"jest": "^30.0
|
|
55
|
-
"prettier": "
|
|
62
|
+
"jest": "^30.2.0",
|
|
63
|
+
"prettier": "3.7.4",
|
|
56
64
|
"reflect-metadata": "^0.2.2",
|
|
57
|
-
"release-it": "19.
|
|
65
|
+
"release-it": "19.2.3",
|
|
58
66
|
"rxjs": "^7.8.2",
|
|
59
|
-
"ts-jest": "
|
|
67
|
+
"ts-jest": "29.4.6",
|
|
60
68
|
"ts-node": "^10.9.2",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"typescript": "^5.9.
|
|
69
|
+
"tsdown": "0.19.0-beta.3",
|
|
70
|
+
"typeorm": "0.3.28",
|
|
71
|
+
"typescript": "^5.9.3"
|
|
64
72
|
},
|
|
65
73
|
"jest": {
|
|
66
74
|
"coveragePathIgnorePatterns": [
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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"}
|