@riktajs/swagger 0.1.2 → 0.1.3
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/constants.d.ts +0 -45
- package/dist/constants.js +0 -50
- package/dist/decorators/api-body.decorator.d.ts +0 -29
- package/dist/decorators/api-body.decorator.js +0 -29
- package/dist/decorators/api-exclude.decorator.d.ts +0 -62
- package/dist/decorators/api-exclude.decorator.js +0 -64
- package/dist/decorators/api-header.decorator.d.ts +0 -21
- package/dist/decorators/api-header.decorator.js +0 -21
- package/dist/decorators/api-operation.decorator.d.ts +0 -28
- package/dist/decorators/api-operation.decorator.js +0 -28
- package/dist/decorators/api-param.decorator.d.ts +0 -24
- package/dist/decorators/api-param.decorator.js +0 -24
- package/dist/decorators/api-property.decorator.d.ts +0 -58
- package/dist/decorators/api-property.decorator.js +0 -56
- package/dist/decorators/api-query.decorator.d.ts +0 -26
- package/dist/decorators/api-query.decorator.js +0 -26
- package/dist/decorators/api-response.decorator.d.ts +0 -55
- package/dist/decorators/api-response.decorator.js +0 -55
- package/dist/decorators/api-security.decorator.d.ts +0 -80
- package/dist/decorators/api-security.decorator.js +0 -84
- package/dist/decorators/api-tags.decorator.d.ts +0 -28
- package/dist/decorators/api-tags.decorator.js +0 -30
- package/dist/decorators/index.d.ts +0 -6
- package/dist/decorators/index.js +0 -14
- package/dist/index.d.ts +0 -55
- package/dist/index.js +0 -62
- package/dist/openapi/generator.d.ts +0 -49
- package/dist/openapi/generator.js +2 -86
- package/dist/openapi/index.d.ts +0 -6
- package/dist/openapi/index.js +0 -9
- package/dist/openapi/zod-to-openapi.d.ts +0 -47
- package/dist/openapi/zod-to-openapi.js +1 -71
- package/dist/plugin/index.d.ts +0 -6
- package/dist/plugin/index.js +0 -6
- package/dist/plugin/swagger.plugin.d.ts +0 -119
- package/dist/plugin/swagger.plugin.js +1 -110
- package/dist/types.d.ts +0 -173
- package/dist/types.js +0 -1
- package/package.json +4 -2
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/decorators/api-body.decorator.d.ts.map +0 -1
- package/dist/decorators/api-body.decorator.js.map +0 -1
- package/dist/decorators/api-exclude.decorator.d.ts.map +0 -1
- package/dist/decorators/api-exclude.decorator.js.map +0 -1
- package/dist/decorators/api-header.decorator.d.ts.map +0 -1
- package/dist/decorators/api-header.decorator.js.map +0 -1
- package/dist/decorators/api-operation.decorator.d.ts.map +0 -1
- package/dist/decorators/api-operation.decorator.js.map +0 -1
- package/dist/decorators/api-param.decorator.d.ts.map +0 -1
- package/dist/decorators/api-param.decorator.js.map +0 -1
- package/dist/decorators/api-property.decorator.d.ts.map +0 -1
- package/dist/decorators/api-property.decorator.js.map +0 -1
- package/dist/decorators/api-query.decorator.d.ts.map +0 -1
- package/dist/decorators/api-query.decorator.js.map +0 -1
- package/dist/decorators/api-response.decorator.d.ts.map +0 -1
- package/dist/decorators/api-response.decorator.js.map +0 -1
- package/dist/decorators/api-security.decorator.d.ts.map +0 -1
- package/dist/decorators/api-security.decorator.js.map +0 -1
- package/dist/decorators/api-tags.decorator.d.ts.map +0 -1
- package/dist/decorators/api-tags.decorator.js.map +0 -1
- package/dist/decorators/index.d.ts.map +0 -1
- package/dist/decorators/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/openapi/generator.d.ts.map +0 -1
- package/dist/openapi/generator.js.map +0 -1
- package/dist/openapi/index.d.ts.map +0 -1
- package/dist/openapi/index.js.map +0 -1
- package/dist/openapi/zod-to-openapi.d.ts.map +0 -1
- package/dist/openapi/zod-to-openapi.js.map +0 -1
- package/dist/plugin/index.d.ts.map +0 -1
- package/dist/plugin/index.js.map +0 -1
- package/dist/plugin/swagger.plugin.d.ts.map +0 -1
- package/dist/plugin/swagger.plugin.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,76 +1,20 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { API_PROPERTY_METADATA } from '../constants.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiProperty() decorator
|
|
5
|
-
*
|
|
6
|
-
* Documents a property of a DTO class for schema generation.
|
|
7
|
-
* Used when you want to manually define schema properties instead of using Zod.
|
|
8
|
-
*
|
|
9
|
-
* @param options - Property options including type, description, and validation rules
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* class CreateUserDto {
|
|
14
|
-
* @ApiProperty({
|
|
15
|
-
* description: 'User email address',
|
|
16
|
-
* type: 'string',
|
|
17
|
-
* format: 'email',
|
|
18
|
-
* example: 'user@example.com',
|
|
19
|
-
* required: true,
|
|
20
|
-
* })
|
|
21
|
-
* email!: string;
|
|
22
|
-
*
|
|
23
|
-
* @ApiProperty({
|
|
24
|
-
* description: 'User age',
|
|
25
|
-
* type: 'integer',
|
|
26
|
-
* minimum: 0,
|
|
27
|
-
* maximum: 150,
|
|
28
|
-
* required: false,
|
|
29
|
-
* })
|
|
30
|
-
* age?: number;
|
|
31
|
-
*
|
|
32
|
-
* @ApiProperty({
|
|
33
|
-
* description: 'User role',
|
|
34
|
-
* enum: ['admin', 'user', 'guest'],
|
|
35
|
-
* default: 'user',
|
|
36
|
-
* })
|
|
37
|
-
* role!: string;
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
3
|
export function ApiProperty(options = {}) {
|
|
42
4
|
return (target, propertyKey) => {
|
|
43
5
|
const existingProperties = Reflect.getMetadata(API_PROPERTY_METADATA, target.constructor) ?? [];
|
|
44
6
|
Reflect.defineMetadata(API_PROPERTY_METADATA, [...existingProperties, { propertyKey, options }], target.constructor);
|
|
45
7
|
};
|
|
46
8
|
}
|
|
47
|
-
/**
|
|
48
|
-
* @ApiPropertyOptional() decorator
|
|
49
|
-
*
|
|
50
|
-
* Shorthand for @ApiProperty({ required: false }).
|
|
51
|
-
* Marks a property as optional in the schema.
|
|
52
|
-
*/
|
|
53
9
|
export function ApiPropertyOptional(options = {}) {
|
|
54
10
|
return ApiProperty({ ...options, required: false });
|
|
55
11
|
}
|
|
56
|
-
/**
|
|
57
|
-
* @ApiHideProperty() decorator
|
|
58
|
-
*
|
|
59
|
-
* Excludes a property from the generated schema.
|
|
60
|
-
* Useful for internal properties that shouldn't be documented.
|
|
61
|
-
*/
|
|
62
12
|
export function ApiHideProperty() {
|
|
63
13
|
return (target, propertyKey) => {
|
|
64
14
|
const existingProperties = Reflect.getMetadata(API_PROPERTY_METADATA, target.constructor) ?? [];
|
|
65
|
-
// Add property with special flag to hide it
|
|
66
15
|
Reflect.defineMetadata(API_PROPERTY_METADATA, [...existingProperties, { propertyKey, options: { _hidden: true } }], target.constructor);
|
|
67
16
|
};
|
|
68
17
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Get all property metadata from a class
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
18
|
export function getApiProperties(target) {
|
|
74
19
|
return Reflect.getMetadata(API_PROPERTY_METADATA, target) ?? [];
|
|
75
20
|
}
|
|
76
|
-
//# sourceMappingURL=api-property.decorator.js.map
|
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { ApiQueryOptions } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiQuery() decorator
|
|
5
|
-
*
|
|
6
|
-
* Documents a query parameter for an API operation.
|
|
7
|
-
* Multiple @ApiQuery decorators can be applied for routes with multiple query parameters.
|
|
8
|
-
*
|
|
9
|
-
* @param options - Query parameter options including name, description, and type
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @Get('/')
|
|
14
|
-
* @ApiQuery({ name: 'page', description: 'Page number', type: 'integer', required: false })
|
|
15
|
-
* @ApiQuery({ name: 'limit', description: 'Items per page', type: 'integer', required: false })
|
|
16
|
-
* @ApiQuery({ name: 'sort', description: 'Sort order', enum: ['asc', 'desc'] })
|
|
17
|
-
* listUsers(
|
|
18
|
-
* @Query('page') page?: number,
|
|
19
|
-
* @Query('limit') limit?: number,
|
|
20
|
-
* @Query('sort') sort?: string
|
|
21
|
-
* ) { }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
3
|
export declare function ApiQuery(options: ApiQueryOptions): MethodDecorator;
|
|
25
|
-
/**
|
|
26
|
-
* Get all query parameter metadata from a method
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
4
|
export declare function getApiQueries(target: Function, propertyKey: string | symbol): ApiQueryOptions[];
|
|
30
|
-
//# sourceMappingURL=api-query.decorator.d.ts.map
|
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { API_QUERY_METADATA } from '../constants.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiQuery() decorator
|
|
5
|
-
*
|
|
6
|
-
* Documents a query parameter for an API operation.
|
|
7
|
-
* Multiple @ApiQuery decorators can be applied for routes with multiple query parameters.
|
|
8
|
-
*
|
|
9
|
-
* @param options - Query parameter options including name, description, and type
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @Get('/')
|
|
14
|
-
* @ApiQuery({ name: 'page', description: 'Page number', type: 'integer', required: false })
|
|
15
|
-
* @ApiQuery({ name: 'limit', description: 'Items per page', type: 'integer', required: false })
|
|
16
|
-
* @ApiQuery({ name: 'sort', description: 'Sort order', enum: ['asc', 'desc'] })
|
|
17
|
-
* listUsers(
|
|
18
|
-
* @Query('page') page?: number,
|
|
19
|
-
* @Query('limit') limit?: number,
|
|
20
|
-
* @Query('sort') sort?: string
|
|
21
|
-
* ) { }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
3
|
export function ApiQuery(options) {
|
|
25
4
|
return (target, propertyKey, descriptor) => {
|
|
26
5
|
const existingQueries = Reflect.getMetadata(API_QUERY_METADATA, target, propertyKey) ?? [];
|
|
@@ -28,11 +7,6 @@ export function ApiQuery(options) {
|
|
|
28
7
|
return descriptor;
|
|
29
8
|
};
|
|
30
9
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Get all query parameter metadata from a method
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
10
|
export function getApiQueries(target, propertyKey) {
|
|
36
11
|
return Reflect.getMetadata(API_QUERY_METADATA, target.prototype, propertyKey) ?? [];
|
|
37
12
|
}
|
|
38
|
-
//# sourceMappingURL=api-query.decorator.js.map
|
|
@@ -1,70 +1,15 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { ApiResponseOptions } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiResponse() decorator
|
|
5
|
-
*
|
|
6
|
-
* Documents a possible response for an API operation.
|
|
7
|
-
* Multiple @ApiResponse decorators can be applied to document different response scenarios.
|
|
8
|
-
*
|
|
9
|
-
* @param options - Response options including status code, description, and schema
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @Get('/:id')
|
|
14
|
-
* @ApiResponse({ status: 200, description: 'User found', schema: UserSchema })
|
|
15
|
-
* @ApiResponse({ status: 404, description: 'User not found' })
|
|
16
|
-
* @ApiResponse({ status: 500, description: 'Internal server error' })
|
|
17
|
-
* getUser(@Param('id') id: string) { }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
3
|
export declare function ApiResponse(options: ApiResponseOptions): MethodDecorator;
|
|
21
|
-
/**
|
|
22
|
-
* @ApiOkResponse() - Shorthand for 200 OK response
|
|
23
|
-
*/
|
|
24
4
|
export declare function ApiOkResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
25
|
-
/**
|
|
26
|
-
* @ApiCreatedResponse() - Shorthand for 201 Created response
|
|
27
|
-
*/
|
|
28
5
|
export declare function ApiCreatedResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
29
|
-
/**
|
|
30
|
-
* @ApiAcceptedResponse() - Shorthand for 202 Accepted response
|
|
31
|
-
*/
|
|
32
6
|
export declare function ApiAcceptedResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
33
|
-
/**
|
|
34
|
-
* @ApiNoContentResponse() - Shorthand for 204 No Content response
|
|
35
|
-
*/
|
|
36
7
|
export declare function ApiNoContentResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
37
|
-
/**
|
|
38
|
-
* @ApiBadRequestResponse() - Shorthand for 400 Bad Request response
|
|
39
|
-
*/
|
|
40
8
|
export declare function ApiBadRequestResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
41
|
-
/**
|
|
42
|
-
* @ApiUnauthorizedResponse() - Shorthand for 401 Unauthorized response
|
|
43
|
-
*/
|
|
44
9
|
export declare function ApiUnauthorizedResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
45
|
-
/**
|
|
46
|
-
* @ApiForbiddenResponse() - Shorthand for 403 Forbidden response
|
|
47
|
-
*/
|
|
48
10
|
export declare function ApiForbiddenResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
49
|
-
/**
|
|
50
|
-
* @ApiNotFoundResponse() - Shorthand for 404 Not Found response
|
|
51
|
-
*/
|
|
52
11
|
export declare function ApiNotFoundResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
53
|
-
/**
|
|
54
|
-
* @ApiConflictResponse() - Shorthand for 409 Conflict response
|
|
55
|
-
*/
|
|
56
12
|
export declare function ApiConflictResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
57
|
-
/**
|
|
58
|
-
* @ApiUnprocessableEntityResponse() - Shorthand for 422 Unprocessable Entity response
|
|
59
|
-
*/
|
|
60
13
|
export declare function ApiUnprocessableEntityResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
61
|
-
/**
|
|
62
|
-
* @ApiInternalServerErrorResponse() - Shorthand for 500 Internal Server Error response
|
|
63
|
-
*/
|
|
64
14
|
export declare function ApiInternalServerErrorResponse(options?: Omit<ApiResponseOptions, 'status'>): MethodDecorator;
|
|
65
|
-
/**
|
|
66
|
-
* Get all response metadata from a method
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
15
|
export declare function getApiResponses(target: Function, propertyKey: string | symbol): ApiResponseOptions[];
|
|
70
|
-
//# sourceMappingURL=api-response.decorator.d.ts.map
|
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { API_RESPONSE_METADATA } from '../constants.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiResponse() decorator
|
|
5
|
-
*
|
|
6
|
-
* Documents a possible response for an API operation.
|
|
7
|
-
* Multiple @ApiResponse decorators can be applied to document different response scenarios.
|
|
8
|
-
*
|
|
9
|
-
* @param options - Response options including status code, description, and schema
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @Get('/:id')
|
|
14
|
-
* @ApiResponse({ status: 200, description: 'User found', schema: UserSchema })
|
|
15
|
-
* @ApiResponse({ status: 404, description: 'User not found' })
|
|
16
|
-
* @ApiResponse({ status: 500, description: 'Internal server error' })
|
|
17
|
-
* getUser(@Param('id') id: string) { }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
3
|
export function ApiResponse(options) {
|
|
21
4
|
return (target, propertyKey, descriptor) => {
|
|
22
5
|
const existingResponses = Reflect.getMetadata(API_RESPONSE_METADATA, target, propertyKey) ?? [];
|
|
@@ -24,77 +7,39 @@ export function ApiResponse(options) {
|
|
|
24
7
|
return descriptor;
|
|
25
8
|
};
|
|
26
9
|
}
|
|
27
|
-
/**
|
|
28
|
-
* @ApiOkResponse() - Shorthand for 200 OK response
|
|
29
|
-
*/
|
|
30
10
|
export function ApiOkResponse(options = {}) {
|
|
31
11
|
return ApiResponse({ ...options, status: 200 });
|
|
32
12
|
}
|
|
33
|
-
/**
|
|
34
|
-
* @ApiCreatedResponse() - Shorthand for 201 Created response
|
|
35
|
-
*/
|
|
36
13
|
export function ApiCreatedResponse(options = {}) {
|
|
37
14
|
return ApiResponse({ ...options, status: 201 });
|
|
38
15
|
}
|
|
39
|
-
/**
|
|
40
|
-
* @ApiAcceptedResponse() - Shorthand for 202 Accepted response
|
|
41
|
-
*/
|
|
42
16
|
export function ApiAcceptedResponse(options = {}) {
|
|
43
17
|
return ApiResponse({ ...options, status: 202 });
|
|
44
18
|
}
|
|
45
|
-
/**
|
|
46
|
-
* @ApiNoContentResponse() - Shorthand for 204 No Content response
|
|
47
|
-
*/
|
|
48
19
|
export function ApiNoContentResponse(options = {}) {
|
|
49
20
|
return ApiResponse({ ...options, status: 204 });
|
|
50
21
|
}
|
|
51
|
-
/**
|
|
52
|
-
* @ApiBadRequestResponse() - Shorthand for 400 Bad Request response
|
|
53
|
-
*/
|
|
54
22
|
export function ApiBadRequestResponse(options = {}) {
|
|
55
23
|
return ApiResponse({ ...options, status: 400, description: options.description ?? 'Bad Request' });
|
|
56
24
|
}
|
|
57
|
-
/**
|
|
58
|
-
* @ApiUnauthorizedResponse() - Shorthand for 401 Unauthorized response
|
|
59
|
-
*/
|
|
60
25
|
export function ApiUnauthorizedResponse(options = {}) {
|
|
61
26
|
return ApiResponse({ ...options, status: 401, description: options.description ?? 'Unauthorized' });
|
|
62
27
|
}
|
|
63
|
-
/**
|
|
64
|
-
* @ApiForbiddenResponse() - Shorthand for 403 Forbidden response
|
|
65
|
-
*/
|
|
66
28
|
export function ApiForbiddenResponse(options = {}) {
|
|
67
29
|
return ApiResponse({ ...options, status: 403, description: options.description ?? 'Forbidden' });
|
|
68
30
|
}
|
|
69
|
-
/**
|
|
70
|
-
* @ApiNotFoundResponse() - Shorthand for 404 Not Found response
|
|
71
|
-
*/
|
|
72
31
|
export function ApiNotFoundResponse(options = {}) {
|
|
73
32
|
return ApiResponse({ ...options, status: 404, description: options.description ?? 'Not Found' });
|
|
74
33
|
}
|
|
75
|
-
/**
|
|
76
|
-
* @ApiConflictResponse() - Shorthand for 409 Conflict response
|
|
77
|
-
*/
|
|
78
34
|
export function ApiConflictResponse(options = {}) {
|
|
79
35
|
return ApiResponse({ ...options, status: 409, description: options.description ?? 'Conflict' });
|
|
80
36
|
}
|
|
81
|
-
/**
|
|
82
|
-
* @ApiUnprocessableEntityResponse() - Shorthand for 422 Unprocessable Entity response
|
|
83
|
-
*/
|
|
84
37
|
export function ApiUnprocessableEntityResponse(options = {}) {
|
|
85
38
|
return ApiResponse({ ...options, status: 422, description: options.description ?? 'Unprocessable Entity' });
|
|
86
39
|
}
|
|
87
|
-
/**
|
|
88
|
-
* @ApiInternalServerErrorResponse() - Shorthand for 500 Internal Server Error response
|
|
89
|
-
*/
|
|
90
40
|
export function ApiInternalServerErrorResponse(options = {}) {
|
|
91
41
|
return ApiResponse({ ...options, status: 500, description: options.description ?? 'Internal Server Error' });
|
|
92
42
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Get all response metadata from a method
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
43
|
export function getApiResponses(target, propertyKey) {
|
|
98
44
|
return Reflect.getMetadata(API_RESPONSE_METADATA, target.prototype, propertyKey) ?? [];
|
|
99
45
|
}
|
|
100
|
-
//# sourceMappingURL=api-response.decorator.js.map
|
|
@@ -1,88 +1,8 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { ApiSecurityOptions } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiSecurity() decorator
|
|
5
|
-
*
|
|
6
|
-
* Applies a security requirement to a controller or method.
|
|
7
|
-
* The security scheme must be defined in the SwaggerConfig.securitySchemes.
|
|
8
|
-
*
|
|
9
|
-
* Can be applied to:
|
|
10
|
-
* - Controller classes (applies to all routes)
|
|
11
|
-
* - Individual route methods
|
|
12
|
-
*
|
|
13
|
-
* @param name - Name of the security scheme
|
|
14
|
-
* @param scopes - Required scopes (for OAuth2)
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* @ApiSecurity('bearerAuth')
|
|
19
|
-
* @Controller('/users')
|
|
20
|
-
* class UserController {
|
|
21
|
-
* @Get('/')
|
|
22
|
-
* listUsers() { } // Protected by bearerAuth
|
|
23
|
-
*
|
|
24
|
-
* @Get('/public')
|
|
25
|
-
* @ApiSecurity() // Remove security for this endpoint
|
|
26
|
-
* getPublicInfo() { }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
3
|
export declare function ApiSecurity(name?: string, scopes?: string[]): ClassDecorator & MethodDecorator;
|
|
31
|
-
/**
|
|
32
|
-
* @ApiBearerAuth() decorator
|
|
33
|
-
*
|
|
34
|
-
* Shorthand for @ApiSecurity('bearerAuth').
|
|
35
|
-
* Applies Bearer token authentication to a controller or method.
|
|
36
|
-
*
|
|
37
|
-
* @param name - Name of the bearer auth scheme (default: 'bearerAuth')
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* @ApiBearerAuth()
|
|
42
|
-
* @Controller('/users')
|
|
43
|
-
* class UserController {
|
|
44
|
-
* @Get('/')
|
|
45
|
-
* listUsers() { } // Requires Bearer token
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
4
|
export declare function ApiBearerAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
50
|
-
/**
|
|
51
|
-
* @ApiBasicAuth() decorator
|
|
52
|
-
*
|
|
53
|
-
* Shorthand for @ApiSecurity('basicAuth').
|
|
54
|
-
* Applies HTTP Basic authentication to a controller or method.
|
|
55
|
-
*
|
|
56
|
-
* @param name - Name of the basic auth scheme (default: 'basicAuth')
|
|
57
|
-
*/
|
|
58
5
|
export declare function ApiBasicAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
59
|
-
/**
|
|
60
|
-
* @ApiOAuth2() decorator
|
|
61
|
-
*
|
|
62
|
-
* Applies OAuth2 authentication with specific scopes.
|
|
63
|
-
*
|
|
64
|
-
* @param scopes - Required OAuth2 scopes
|
|
65
|
-
* @param name - Name of the OAuth2 scheme (default: 'oauth2')
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* @ApiOAuth2(['read:users', 'write:users'])
|
|
70
|
-
* @Controller('/users')
|
|
71
|
-
* class UserController { }
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
6
|
export declare function ApiOAuth2(scopes?: string[], name?: string): ClassDecorator & MethodDecorator;
|
|
75
|
-
/**
|
|
76
|
-
* @ApiCookieAuth() decorator
|
|
77
|
-
*
|
|
78
|
-
* Applies cookie-based authentication.
|
|
79
|
-
*
|
|
80
|
-
* @param name - Name of the cookie auth scheme (default: 'cookieAuth')
|
|
81
|
-
*/
|
|
82
7
|
export declare function ApiCookieAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
83
|
-
/**
|
|
84
|
-
* Get security metadata from a class or method
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
8
|
export declare function getApiSecurity(target: Function, propertyKey?: string | symbol): ApiSecurityOptions | null | undefined;
|
|
88
|
-
//# sourceMappingURL=api-security.decorator.d.ts.map
|
|
@@ -1,119 +1,35 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { API_SECURITY_METADATA } from '../constants.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiSecurity() decorator
|
|
5
|
-
*
|
|
6
|
-
* Applies a security requirement to a controller or method.
|
|
7
|
-
* The security scheme must be defined in the SwaggerConfig.securitySchemes.
|
|
8
|
-
*
|
|
9
|
-
* Can be applied to:
|
|
10
|
-
* - Controller classes (applies to all routes)
|
|
11
|
-
* - Individual route methods
|
|
12
|
-
*
|
|
13
|
-
* @param name - Name of the security scheme
|
|
14
|
-
* @param scopes - Required scopes (for OAuth2)
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* @ApiSecurity('bearerAuth')
|
|
19
|
-
* @Controller('/users')
|
|
20
|
-
* class UserController {
|
|
21
|
-
* @Get('/')
|
|
22
|
-
* listUsers() { } // Protected by bearerAuth
|
|
23
|
-
*
|
|
24
|
-
* @Get('/public')
|
|
25
|
-
* @ApiSecurity() // Remove security for this endpoint
|
|
26
|
-
* getPublicInfo() { }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
3
|
export function ApiSecurity(name, scopes = []) {
|
|
31
4
|
return (target, propertyKey, descriptor) => {
|
|
32
5
|
const security = name ? { name, scopes } : null;
|
|
33
6
|
if (propertyKey !== undefined && descriptor !== undefined) {
|
|
34
|
-
// Method decorator - save on target (prototype)
|
|
35
7
|
Reflect.defineMetadata(API_SECURITY_METADATA, security, target, propertyKey);
|
|
36
8
|
}
|
|
37
9
|
else {
|
|
38
|
-
// Class decorator
|
|
39
10
|
Reflect.defineMetadata(API_SECURITY_METADATA, security, target);
|
|
40
11
|
}
|
|
41
12
|
};
|
|
42
13
|
}
|
|
43
|
-
/**
|
|
44
|
-
* @ApiBearerAuth() decorator
|
|
45
|
-
*
|
|
46
|
-
* Shorthand for @ApiSecurity('bearerAuth').
|
|
47
|
-
* Applies Bearer token authentication to a controller or method.
|
|
48
|
-
*
|
|
49
|
-
* @param name - Name of the bearer auth scheme (default: 'bearerAuth')
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* @ApiBearerAuth()
|
|
54
|
-
* @Controller('/users')
|
|
55
|
-
* class UserController {
|
|
56
|
-
* @Get('/')
|
|
57
|
-
* listUsers() { } // Requires Bearer token
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
14
|
export function ApiBearerAuth(name = 'bearerAuth') {
|
|
62
15
|
return ApiSecurity(name);
|
|
63
16
|
}
|
|
64
|
-
/**
|
|
65
|
-
* @ApiBasicAuth() decorator
|
|
66
|
-
*
|
|
67
|
-
* Shorthand for @ApiSecurity('basicAuth').
|
|
68
|
-
* Applies HTTP Basic authentication to a controller or method.
|
|
69
|
-
*
|
|
70
|
-
* @param name - Name of the basic auth scheme (default: 'basicAuth')
|
|
71
|
-
*/
|
|
72
17
|
export function ApiBasicAuth(name = 'basicAuth') {
|
|
73
18
|
return ApiSecurity(name);
|
|
74
19
|
}
|
|
75
|
-
/**
|
|
76
|
-
* @ApiOAuth2() decorator
|
|
77
|
-
*
|
|
78
|
-
* Applies OAuth2 authentication with specific scopes.
|
|
79
|
-
*
|
|
80
|
-
* @param scopes - Required OAuth2 scopes
|
|
81
|
-
* @param name - Name of the OAuth2 scheme (default: 'oauth2')
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* @ApiOAuth2(['read:users', 'write:users'])
|
|
86
|
-
* @Controller('/users')
|
|
87
|
-
* class UserController { }
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
20
|
export function ApiOAuth2(scopes = [], name = 'oauth2') {
|
|
91
21
|
return ApiSecurity(name, scopes);
|
|
92
22
|
}
|
|
93
|
-
/**
|
|
94
|
-
* @ApiCookieAuth() decorator
|
|
95
|
-
*
|
|
96
|
-
* Applies cookie-based authentication.
|
|
97
|
-
*
|
|
98
|
-
* @param name - Name of the cookie auth scheme (default: 'cookieAuth')
|
|
99
|
-
*/
|
|
100
23
|
export function ApiCookieAuth(name = 'cookieAuth') {
|
|
101
24
|
return ApiSecurity(name);
|
|
102
25
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Get security metadata from a class or method
|
|
105
|
-
* @internal
|
|
106
|
-
*/
|
|
107
26
|
export function getApiSecurity(target, propertyKey) {
|
|
108
27
|
if (propertyKey !== undefined) {
|
|
109
|
-
// Check if method has explicit security (including null for "no security")
|
|
110
28
|
const methodSecurity = Reflect.getMetadata(API_SECURITY_METADATA, target.prototype, propertyKey);
|
|
111
29
|
if (methodSecurity !== undefined) {
|
|
112
30
|
return methodSecurity;
|
|
113
31
|
}
|
|
114
|
-
// Fall back to class-level security
|
|
115
32
|
return Reflect.getMetadata(API_SECURITY_METADATA, target);
|
|
116
33
|
}
|
|
117
34
|
return Reflect.getMetadata(API_SECURITY_METADATA, target);
|
|
118
35
|
}
|
|
119
|
-
//# sourceMappingURL=api-security.decorator.js.map
|
|
@@ -1,31 +1,3 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
/**
|
|
3
|
-
* @ApiTags() decorator
|
|
4
|
-
*
|
|
5
|
-
* Groups endpoints under one or more tags in the Swagger UI.
|
|
6
|
-
* Tags are used to organize operations in the documentation.
|
|
7
|
-
*
|
|
8
|
-
* Can be applied to:
|
|
9
|
-
* - Controller classes (applies to all routes in the controller)
|
|
10
|
-
* - Individual route methods (overrides or adds to controller tags)
|
|
11
|
-
*
|
|
12
|
-
* @param tags - One or more tag names
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* @ApiTags('Users', 'Authentication')
|
|
17
|
-
* @Controller('/users')
|
|
18
|
-
* class UserController {
|
|
19
|
-
* @Get('/')
|
|
20
|
-
* @ApiTags('Admin') // Adds 'Admin' tag to this specific route
|
|
21
|
-
* listUsers() { }
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
2
|
export declare function ApiTags(...tags: string[]): ClassDecorator & MethodDecorator;
|
|
26
|
-
/**
|
|
27
|
-
* Get tags metadata from a class or method
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
3
|
export declare function getApiTags(target: Function, propertyKey?: string | symbol): string[];
|
|
31
|
-
//# sourceMappingURL=api-tags.decorator.d.ts.map
|
|
@@ -1,46 +1,17 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { API_TAGS_METADATA } from '../constants.js';
|
|
3
|
-
/**
|
|
4
|
-
* @ApiTags() decorator
|
|
5
|
-
*
|
|
6
|
-
* Groups endpoints under one or more tags in the Swagger UI.
|
|
7
|
-
* Tags are used to organize operations in the documentation.
|
|
8
|
-
*
|
|
9
|
-
* Can be applied to:
|
|
10
|
-
* - Controller classes (applies to all routes in the controller)
|
|
11
|
-
* - Individual route methods (overrides or adds to controller tags)
|
|
12
|
-
*
|
|
13
|
-
* @param tags - One or more tag names
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* @ApiTags('Users', 'Authentication')
|
|
18
|
-
* @Controller('/users')
|
|
19
|
-
* class UserController {
|
|
20
|
-
* @Get('/')
|
|
21
|
-
* @ApiTags('Admin') // Adds 'Admin' tag to this specific route
|
|
22
|
-
* listUsers() { }
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
3
|
export function ApiTags(...tags) {
|
|
27
4
|
return (target, propertyKey, descriptor) => {
|
|
28
5
|
if (propertyKey !== undefined && descriptor !== undefined) {
|
|
29
|
-
// Method decorator - save on target (prototype)
|
|
30
6
|
const existingTags = Reflect.getMetadata(API_TAGS_METADATA, target, propertyKey) ?? [];
|
|
31
7
|
Reflect.defineMetadata(API_TAGS_METADATA, [...existingTags, ...tags], target, propertyKey);
|
|
32
8
|
}
|
|
33
9
|
else {
|
|
34
|
-
// Class decorator
|
|
35
10
|
const existingTags = Reflect.getMetadata(API_TAGS_METADATA, target) ?? [];
|
|
36
11
|
Reflect.defineMetadata(API_TAGS_METADATA, [...existingTags, ...tags], target);
|
|
37
12
|
}
|
|
38
13
|
};
|
|
39
14
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Get tags metadata from a class or method
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
15
|
export function getApiTags(target, propertyKey) {
|
|
45
16
|
if (propertyKey !== undefined) {
|
|
46
17
|
const methodTags = Reflect.getMetadata(API_TAGS_METADATA, target.prototype, propertyKey) ?? [];
|
|
@@ -49,4 +20,3 @@ export function getApiTags(target, propertyKey) {
|
|
|
49
20
|
}
|
|
50
21
|
return Reflect.getMetadata(API_TAGS_METADATA, target) ?? [];
|
|
51
22
|
}
|
|
52
|
-
//# sourceMappingURL=api-tags.decorator.js.map
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swagger decorators barrel export
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
1
|
export { ApiTags, getApiTags } from './api-tags.decorator.js';
|
|
7
2
|
export { ApiOperation, getApiOperation } from './api-operation.decorator.js';
|
|
8
3
|
export { ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiAcceptedResponse, ApiNoContentResponse, ApiBadRequestResponse, ApiUnauthorizedResponse, ApiForbiddenResponse, ApiNotFoundResponse, ApiConflictResponse, ApiUnprocessableEntityResponse, ApiInternalServerErrorResponse, getApiResponses, } from './api-response.decorator.js';
|
|
@@ -13,4 +8,3 @@ export { ApiHeader, getApiHeaders } from './api-header.decorator.js';
|
|
|
13
8
|
export { ApiSecurity, ApiBearerAuth, ApiBasicAuth, ApiOAuth2, ApiCookieAuth, getApiSecurity, } from './api-security.decorator.js';
|
|
14
9
|
export { ApiProperty, ApiPropertyOptional, ApiHideProperty, getApiProperties, } from './api-property.decorator.js';
|
|
15
10
|
export { ApiExcludeEndpoint, ApiExcludeController, isApiExcluded, ApiDeprecated, getApiDeprecated, } from './api-exclude.decorator.js';
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swagger decorators barrel export
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
// Tag decorator
|
|
7
1
|
export { ApiTags, getApiTags } from './api-tags.decorator.js';
|
|
8
|
-
// Operation decorator
|
|
9
2
|
export { ApiOperation, getApiOperation } from './api-operation.decorator.js';
|
|
10
|
-
// Response decorators
|
|
11
3
|
export { ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiAcceptedResponse, ApiNoContentResponse, ApiBadRequestResponse, ApiUnauthorizedResponse, ApiForbiddenResponse, ApiNotFoundResponse, ApiConflictResponse, ApiUnprocessableEntityResponse, ApiInternalServerErrorResponse, getApiResponses, } from './api-response.decorator.js';
|
|
12
|
-
// Body decorator
|
|
13
4
|
export { ApiBody, getApiBody } from './api-body.decorator.js';
|
|
14
|
-
// Parameter decorators
|
|
15
5
|
export { ApiParam, getApiParams } from './api-param.decorator.js';
|
|
16
6
|
export { ApiQuery, getApiQueries } from './api-query.decorator.js';
|
|
17
7
|
export { ApiHeader, getApiHeaders } from './api-header.decorator.js';
|
|
18
|
-
// Security decorators
|
|
19
8
|
export { ApiSecurity, ApiBearerAuth, ApiBasicAuth, ApiOAuth2, ApiCookieAuth, getApiSecurity, } from './api-security.decorator.js';
|
|
20
|
-
// Property decorators
|
|
21
9
|
export { ApiProperty, ApiPropertyOptional, ApiHideProperty, getApiProperties, } from './api-property.decorator.js';
|
|
22
|
-
// Exclude/Deprecate decorators
|
|
23
10
|
export { ApiExcludeEndpoint, ApiExcludeController, isApiExcluded, ApiDeprecated, getApiDeprecated, } from './api-exclude.decorator.js';
|
|
24
|
-
//# sourceMappingURL=index.js.map
|