@riktajs/swagger 0.1.0
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 +258 -0
- package/dist/constants.d.ts +56 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +61 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/api-body.decorator.d.ts +33 -0
- package/dist/decorators/api-body.decorator.d.ts.map +1 -0
- package/dist/decorators/api-body.decorator.js +40 -0
- package/dist/decorators/api-body.decorator.js.map +1 -0
- package/dist/decorators/api-exclude.decorator.d.ts +71 -0
- package/dist/decorators/api-exclude.decorator.d.ts.map +1 -0
- package/dist/decorators/api-exclude.decorator.js +95 -0
- package/dist/decorators/api-exclude.decorator.js.map +1 -0
- package/dist/decorators/api-header.decorator.d.ts +25 -0
- package/dist/decorators/api-header.decorator.d.ts.map +1 -0
- package/dist/decorators/api-header.decorator.js +33 -0
- package/dist/decorators/api-header.decorator.js.map +1 -0
- package/dist/decorators/api-operation.decorator.d.ts +32 -0
- package/dist/decorators/api-operation.decorator.d.ts.map +1 -0
- package/dist/decorators/api-operation.decorator.js +39 -0
- package/dist/decorators/api-operation.decorator.js.map +1 -0
- package/dist/decorators/api-param.decorator.d.ts +28 -0
- package/dist/decorators/api-param.decorator.d.ts.map +1 -0
- package/dist/decorators/api-param.decorator.js +36 -0
- package/dist/decorators/api-param.decorator.js.map +1 -0
- package/dist/decorators/api-property.decorator.d.ts +69 -0
- package/dist/decorators/api-property.decorator.d.ts.map +1 -0
- package/dist/decorators/api-property.decorator.js +76 -0
- package/dist/decorators/api-property.decorator.js.map +1 -0
- package/dist/decorators/api-query.decorator.d.ts +30 -0
- package/dist/decorators/api-query.decorator.d.ts.map +1 -0
- package/dist/decorators/api-query.decorator.js +38 -0
- package/dist/decorators/api-query.decorator.js.map +1 -0
- package/dist/decorators/api-response.decorator.d.ts +70 -0
- package/dist/decorators/api-response.decorator.d.ts.map +1 -0
- package/dist/decorators/api-response.decorator.js +100 -0
- package/dist/decorators/api-response.decorator.js.map +1 -0
- package/dist/decorators/api-security.decorator.d.ts +88 -0
- package/dist/decorators/api-security.decorator.d.ts.map +1 -0
- package/dist/decorators/api-security.decorator.js +119 -0
- package/dist/decorators/api-security.decorator.js.map +1 -0
- package/dist/decorators/api-tags.decorator.d.ts +31 -0
- package/dist/decorators/api-tags.decorator.d.ts.map +1 -0
- package/dist/decorators/api-tags.decorator.js +52 -0
- package/dist/decorators/api-tags.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +16 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +24 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi/generator.d.ts +98 -0
- package/dist/openapi/generator.d.ts.map +1 -0
- package/dist/openapi/generator.js +493 -0
- package/dist/openapi/generator.js.map +1 -0
- package/dist/openapi/index.d.ts +8 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +11 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi/zod-to-openapi.d.ts +52 -0
- package/dist/openapi/zod-to-openapi.d.ts.map +1 -0
- package/dist/openapi/zod-to-openapi.js +172 -0
- package/dist/openapi/zod-to-openapi.js.map +1 -0
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +7 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/swagger.plugin.d.ts +157 -0
- package/dist/plugin/swagger.plugin.d.ts.map +1 -0
- package/dist/plugin/swagger.plugin.js +235 -0
- package/dist/plugin/swagger.plugin.js.map +1 -0
- package/dist/types.d.ts +511 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
export declare function ApiCookieAuth(name?: string): ClassDecorator & MethodDecorator;
|
|
83
|
+
/**
|
|
84
|
+
* Get security metadata from a class or method
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
export declare function getApiSecurity(target: Function, propertyKey?: string | symbol): ApiSecurityOptions | null | undefined;
|
|
88
|
+
//# sourceMappingURL=api-security.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-security.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/api-security.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CACzB,IAAI,CAAC,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,EAAO,GACpB,cAAc,GAAG,eAAe,CAqBlC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAqB,GAAG,cAAc,GAAG,eAAe,CAE3F;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,MAAoB,GAAG,cAAc,GAAG,eAAe,CAEzF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CACvB,MAAM,GAAE,MAAM,EAAO,EACrB,IAAI,GAAE,MAAiB,GACtB,cAAc,GAAG,eAAe,CAElC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAqB,GAAG,cAAc,GAAG,eAAe,CAE3F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,QAAQ,EAChB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAC5B,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAWvC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
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
|
+
export function ApiSecurity(name, scopes = []) {
|
|
31
|
+
return (target, propertyKey, descriptor) => {
|
|
32
|
+
const security = name ? { name, scopes } : null;
|
|
33
|
+
if (propertyKey !== undefined && descriptor !== undefined) {
|
|
34
|
+
// Method decorator - save on target (prototype)
|
|
35
|
+
Reflect.defineMetadata(API_SECURITY_METADATA, security, target, propertyKey);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Class decorator
|
|
39
|
+
Reflect.defineMetadata(API_SECURITY_METADATA, security, target);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
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
|
+
export function ApiBearerAuth(name = 'bearerAuth') {
|
|
62
|
+
return ApiSecurity(name);
|
|
63
|
+
}
|
|
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
|
+
export function ApiBasicAuth(name = 'basicAuth') {
|
|
73
|
+
return ApiSecurity(name);
|
|
74
|
+
}
|
|
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
|
+
export function ApiOAuth2(scopes = [], name = 'oauth2') {
|
|
91
|
+
return ApiSecurity(name, scopes);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @ApiCookieAuth() decorator
|
|
95
|
+
*
|
|
96
|
+
* Applies cookie-based authentication.
|
|
97
|
+
*
|
|
98
|
+
* @param name - Name of the cookie auth scheme (default: 'cookieAuth')
|
|
99
|
+
*/
|
|
100
|
+
export function ApiCookieAuth(name = 'cookieAuth') {
|
|
101
|
+
return ApiSecurity(name);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get security metadata from a class or method
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export function getApiSecurity(target, propertyKey) {
|
|
108
|
+
if (propertyKey !== undefined) {
|
|
109
|
+
// Check if method has explicit security (including null for "no security")
|
|
110
|
+
const methodSecurity = Reflect.getMetadata(API_SECURITY_METADATA, target.prototype, propertyKey);
|
|
111
|
+
if (methodSecurity !== undefined) {
|
|
112
|
+
return methodSecurity;
|
|
113
|
+
}
|
|
114
|
+
// Fall back to class-level security
|
|
115
|
+
return Reflect.getMetadata(API_SECURITY_METADATA, target);
|
|
116
|
+
}
|
|
117
|
+
return Reflect.getMetadata(API_SECURITY_METADATA, target);
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=api-security.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-security.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-security.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,WAAW,CACzB,IAAa,EACb,SAAmB,EAAE;IAErB,OAAO,CACL,MAAyB,EACzB,WAA6B,EAC7B,UAA+B,EACzB,EAAE;QACR,MAAM,QAAQ,GAA8B,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAE3E,IAAI,WAAW,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC1D,gDAAgD;YAChD,OAAO,CAAC,cAAc,CACpB,qBAAqB,EACrB,QAAQ,EACR,MAAM,EACN,WAAW,CACZ,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,kBAAkB;YAClB,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClE,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,YAAY;IACvD,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,WAAW;IACrD,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CACvB,SAAmB,EAAE,EACrB,OAAe,QAAQ;IAEvB,OAAO,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,YAAY;IACvD,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAgB,EAChB,WAA6B;IAE7B,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,2EAA2E;QAC3E,MAAM,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACjG,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,oCAAoC;QACpC,OAAO,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
export declare function ApiTags(...tags: string[]): ClassDecorator & MethodDecorator;
|
|
26
|
+
/**
|
|
27
|
+
* Get tags metadata from a class or method
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function getApiTags(target: Function, propertyKey?: string | symbol): string[];
|
|
31
|
+
//# sourceMappingURL=api-tags.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-tags.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/api-tags.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,cAAc,GAAG,eAAe,CA2B3E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CASpF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
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
|
+
export function ApiTags(...tags) {
|
|
27
|
+
return (target, propertyKey, descriptor) => {
|
|
28
|
+
if (propertyKey !== undefined && descriptor !== undefined) {
|
|
29
|
+
// Method decorator - save on target (prototype)
|
|
30
|
+
const existingTags = Reflect.getMetadata(API_TAGS_METADATA, target, propertyKey) ?? [];
|
|
31
|
+
Reflect.defineMetadata(API_TAGS_METADATA, [...existingTags, ...tags], target, propertyKey);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Class decorator
|
|
35
|
+
const existingTags = Reflect.getMetadata(API_TAGS_METADATA, target) ?? [];
|
|
36
|
+
Reflect.defineMetadata(API_TAGS_METADATA, [...existingTags, ...tags], target);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get tags metadata from a class or method
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export function getApiTags(target, propertyKey) {
|
|
45
|
+
if (propertyKey !== undefined) {
|
|
46
|
+
const methodTags = Reflect.getMetadata(API_TAGS_METADATA, target.prototype, propertyKey) ?? [];
|
|
47
|
+
const classTags = Reflect.getMetadata(API_TAGS_METADATA, target) ?? [];
|
|
48
|
+
return [...new Set([...classTags, ...methodTags])];
|
|
49
|
+
}
|
|
50
|
+
return Reflect.getMetadata(API_TAGS_METADATA, target) ?? [];
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=api-tags.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-tags.decorator.js","sourceRoot":"","sources":["../../src/decorators/api-tags.decorator.ts"],"names":[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,CAAC;IACrD,CAAC;IACD,OAAO,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swagger decorators barrel export
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { ApiTags, getApiTags } from './api-tags.decorator.js';
|
|
7
|
+
export { ApiOperation, getApiOperation } from './api-operation.decorator.js';
|
|
8
|
+
export { ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiAcceptedResponse, ApiNoContentResponse, ApiBadRequestResponse, ApiUnauthorizedResponse, ApiForbiddenResponse, ApiNotFoundResponse, ApiConflictResponse, ApiUnprocessableEntityResponse, ApiInternalServerErrorResponse, getApiResponses, } from './api-response.decorator.js';
|
|
9
|
+
export { ApiBody, getApiBody } from './api-body.decorator.js';
|
|
10
|
+
export { ApiParam, getApiParams } from './api-param.decorator.js';
|
|
11
|
+
export { ApiQuery, getApiQueries } from './api-query.decorator.js';
|
|
12
|
+
export { ApiHeader, getApiHeaders } from './api-header.decorator.js';
|
|
13
|
+
export { ApiSecurity, ApiBearerAuth, ApiBasicAuth, ApiOAuth2, ApiCookieAuth, getApiSecurity, } from './api-security.decorator.js';
|
|
14
|
+
export { ApiProperty, ApiPropertyOptional, ApiHideProperty, getApiProperties, } from './api-property.decorator.js';
|
|
15
|
+
export { ApiExcludeEndpoint, ApiExcludeController, isApiExcluded, ApiDeprecated, getApiDeprecated, } from './api-exclude.decorator.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG7E,OAAO,EACL,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,8BAA8B,EAC9B,8BAA8B,EAC9B,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGrE,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,EACT,aAAa,EACb,cAAc,GACf,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swagger decorators barrel export
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
// Tag decorator
|
|
7
|
+
export { ApiTags, getApiTags } from './api-tags.decorator.js';
|
|
8
|
+
// Operation decorator
|
|
9
|
+
export { ApiOperation, getApiOperation } from './api-operation.decorator.js';
|
|
10
|
+
// Response decorators
|
|
11
|
+
export { ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiAcceptedResponse, ApiNoContentResponse, ApiBadRequestResponse, ApiUnauthorizedResponse, ApiForbiddenResponse, ApiNotFoundResponse, ApiConflictResponse, ApiUnprocessableEntityResponse, ApiInternalServerErrorResponse, getApiResponses, } from './api-response.decorator.js';
|
|
12
|
+
// Body decorator
|
|
13
|
+
export { ApiBody, getApiBody } from './api-body.decorator.js';
|
|
14
|
+
// Parameter decorators
|
|
15
|
+
export { ApiParam, getApiParams } from './api-param.decorator.js';
|
|
16
|
+
export { ApiQuery, getApiQueries } from './api-query.decorator.js';
|
|
17
|
+
export { ApiHeader, getApiHeaders } from './api-header.decorator.js';
|
|
18
|
+
// Security decorators
|
|
19
|
+
export { ApiSecurity, ApiBearerAuth, ApiBasicAuth, ApiOAuth2, ApiCookieAuth, getApiSecurity, } from './api-security.decorator.js';
|
|
20
|
+
// Property decorators
|
|
21
|
+
export { ApiProperty, ApiPropertyOptional, ApiHideProperty, getApiProperties, } from './api-property.decorator.js';
|
|
22
|
+
// Exclude/Deprecate decorators
|
|
23
|
+
export { ApiExcludeEndpoint, ApiExcludeController, isApiExcluded, ApiDeprecated, getApiDeprecated, } from './api-exclude.decorator.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9D,sBAAsB;AACtB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE7E,sBAAsB;AACtB,OAAO,EACL,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,8BAA8B,EAC9B,8BAA8B,EAC9B,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAErC,iBAAiB;AACjB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9D,uBAAuB;AACvB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAErE,sBAAsB;AACtB,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,EACT,aAAa,EACb,cAAc,GACf,MAAM,6BAA6B,CAAC;AAErC,sBAAsB;AACtB,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AAErC,+BAA+B;AAC/B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,4BAA4B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/swagger
|
|
3
|
+
*
|
|
4
|
+
* Automatic OpenAPI/Swagger documentation generation for Rikta Framework.
|
|
5
|
+
*
|
|
6
|
+
* This package provides decorators and utilities to automatically generate
|
|
7
|
+
* OpenAPI 3.0/3.1 documentation from your Rikta controllers and routes.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Automatic route extraction from @Controller, @Get, @Post, etc.
|
|
11
|
+
* - Decorators for enriching API documentation (@ApiTags, @ApiOperation, @ApiResponse, etc.)
|
|
12
|
+
* - Zod schema integration for automatic request/response type documentation
|
|
13
|
+
* - Interactive Swagger UI served via Fastify
|
|
14
|
+
* - Full OpenAPI 3.0/3.1 specification support
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { Rikta, Controller, Get } from '@riktajs/core';
|
|
19
|
+
* import { swaggerPlugin, ApiTags, ApiOperation, ApiResponse } from '@riktajs/swagger';
|
|
20
|
+
* import { z } from 'zod';
|
|
21
|
+
*
|
|
22
|
+
* const UserSchema = z.object({
|
|
23
|
+
* id: z.string().uuid(),
|
|
24
|
+
* name: z.string(),
|
|
25
|
+
* email: z.string().email(),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* @ApiTags('Users')
|
|
29
|
+
* @Controller('/users')
|
|
30
|
+
* class UserController {
|
|
31
|
+
* @Get('/')
|
|
32
|
+
* @ApiOperation({ summary: 'List all users' })
|
|
33
|
+
* @ApiResponse({ status: 200, description: 'Array of users', schema: z.array(UserSchema) })
|
|
34
|
+
* async listUsers() {
|
|
35
|
+
* return [];
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* const app = await Rikta.create({ port: 3000 });
|
|
40
|
+
*
|
|
41
|
+
* // Register swagger plugin
|
|
42
|
+
* app.server.register(swaggerPlugin, {
|
|
43
|
+
* title: 'My API',
|
|
44
|
+
* version: '1.0.0',
|
|
45
|
+
* description: 'My awesome API documentation',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* await app.listen();
|
|
49
|
+
* // Swagger UI available at http://localhost:3000/docs
|
|
50
|
+
* // OpenAPI JSON available at http://localhost:3000/docs/json
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @packageDocumentation
|
|
54
|
+
*/
|
|
55
|
+
export * from './constants.js';
|
|
56
|
+
export { CONTROLLER_METADATA, ROUTES_METADATA, PARAM_METADATA, HTTP_CODE_METADATA, GUARDS_METADATA, ZOD_SCHEMA_METADATA, } from '@riktajs/core';
|
|
57
|
+
export type * from './types.js';
|
|
58
|
+
export * from './decorators/index.js';
|
|
59
|
+
export { OpenApiGenerator } from './openapi/generator.js';
|
|
60
|
+
export { zodToOpenApi, toOpenApiSchema, isZodSchema } from './openapi/zod-to-openapi.js';
|
|
61
|
+
export { swaggerPlugin, registerSwagger, createSwaggerConfig } from './plugin/swagger.plugin.js';
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAGH,cAAc,gBAAgB,CAAC;AAI/B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAGvB,mBAAmB,YAAY,CAAC;AAGhC,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGzF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @riktajs/swagger
|
|
3
|
+
*
|
|
4
|
+
* Automatic OpenAPI/Swagger documentation generation for Rikta Framework.
|
|
5
|
+
*
|
|
6
|
+
* This package provides decorators and utilities to automatically generate
|
|
7
|
+
* OpenAPI 3.0/3.1 documentation from your Rikta controllers and routes.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Automatic route extraction from @Controller, @Get, @Post, etc.
|
|
11
|
+
* - Decorators for enriching API documentation (@ApiTags, @ApiOperation, @ApiResponse, etc.)
|
|
12
|
+
* - Zod schema integration for automatic request/response type documentation
|
|
13
|
+
* - Interactive Swagger UI served via Fastify
|
|
14
|
+
* - Full OpenAPI 3.0/3.1 specification support
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { Rikta, Controller, Get } from '@riktajs/core';
|
|
19
|
+
* import { swaggerPlugin, ApiTags, ApiOperation, ApiResponse } from '@riktajs/swagger';
|
|
20
|
+
* import { z } from 'zod';
|
|
21
|
+
*
|
|
22
|
+
* const UserSchema = z.object({
|
|
23
|
+
* id: z.string().uuid(),
|
|
24
|
+
* name: z.string(),
|
|
25
|
+
* email: z.string().email(),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* @ApiTags('Users')
|
|
29
|
+
* @Controller('/users')
|
|
30
|
+
* class UserController {
|
|
31
|
+
* @Get('/')
|
|
32
|
+
* @ApiOperation({ summary: 'List all users' })
|
|
33
|
+
* @ApiResponse({ status: 200, description: 'Array of users', schema: z.array(UserSchema) })
|
|
34
|
+
* async listUsers() {
|
|
35
|
+
* return [];
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* const app = await Rikta.create({ port: 3000 });
|
|
40
|
+
*
|
|
41
|
+
* // Register swagger plugin
|
|
42
|
+
* app.server.register(swaggerPlugin, {
|
|
43
|
+
* title: 'My API',
|
|
44
|
+
* version: '1.0.0',
|
|
45
|
+
* description: 'My awesome API documentation',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* await app.listen();
|
|
49
|
+
* // Swagger UI available at http://localhost:3000/docs
|
|
50
|
+
* // OpenAPI JSON available at http://localhost:3000/docs/json
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @packageDocumentation
|
|
54
|
+
*/
|
|
55
|
+
// Export swagger-specific constants
|
|
56
|
+
export * from './constants.js';
|
|
57
|
+
// Re-export core constants needed for metadata reading
|
|
58
|
+
// These are imported from @riktajs/core to avoid duplication
|
|
59
|
+
export { CONTROLLER_METADATA, ROUTES_METADATA, PARAM_METADATA, HTTP_CODE_METADATA, GUARDS_METADATA, ZOD_SCHEMA_METADATA, } from '@riktajs/core';
|
|
60
|
+
// Export decorators
|
|
61
|
+
export * from './decorators/index.js';
|
|
62
|
+
// Export OpenAPI generator
|
|
63
|
+
export { OpenApiGenerator } from './openapi/generator.js';
|
|
64
|
+
// Export Zod-to-OpenAPI utilities
|
|
65
|
+
export { zodToOpenApi, toOpenApiSchema, isZodSchema } from './openapi/zod-to-openapi.js';
|
|
66
|
+
// Export Fastify plugin
|
|
67
|
+
export { swaggerPlugin, registerSwagger, createSwaggerConfig } from './plugin/swagger.plugin.js';
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,oCAAoC;AACpC,cAAc,gBAAgB,CAAC;AAE/B,uDAAuD;AACvD,6DAA6D;AAC7D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAKvB,oBAAoB;AACpB,cAAc,uBAAuB,CAAC;AAEtC,2BAA2B;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,kCAAkC;AAClC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAEzF,wBAAwB;AACxB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { SwaggerConfig, OpenApiDocument, OpenApiSecurityScheme, OpenApiInfoObject } from '../types.js';
|
|
3
|
+
type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
4
|
+
/**
|
|
5
|
+
* Shorthand config options that allow flat title/version/description
|
|
6
|
+
*/
|
|
7
|
+
interface OpenApiGeneratorConfig extends Omit<SwaggerConfig, 'info'> {
|
|
8
|
+
/** API title (shorthand for info.title) */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** API version (shorthand for info.version) */
|
|
11
|
+
version?: string;
|
|
12
|
+
/** API description (shorthand for info.description) */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** API contact (shorthand for info.contact) */
|
|
15
|
+
contact?: OpenApiInfoObject['contact'];
|
|
16
|
+
/** API license (shorthand for info.license) */
|
|
17
|
+
license?: OpenApiInfoObject['license'];
|
|
18
|
+
/** API terms of service (shorthand for info.termsOfService) */
|
|
19
|
+
termsOfService?: string;
|
|
20
|
+
/** Full info object (takes precedence over shorthand) */
|
|
21
|
+
info?: OpenApiInfoObject;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* OpenAPI Specification Generator
|
|
25
|
+
*
|
|
26
|
+
* Collects metadata from controllers and generates a complete
|
|
27
|
+
* OpenAPI 3.0.3 specification document.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const generator = new OpenApiGenerator({
|
|
32
|
+
* info: {
|
|
33
|
+
* title: 'My API',
|
|
34
|
+
* version: '1.0.0',
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Add controllers to scan
|
|
39
|
+
* generator.addController(UserController);
|
|
40
|
+
* generator.addController(ProductController);
|
|
41
|
+
*
|
|
42
|
+
* // Generate the specification
|
|
43
|
+
* const spec = generator.generate();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class OpenApiGenerator {
|
|
47
|
+
private config;
|
|
48
|
+
private controllers;
|
|
49
|
+
private globalSecuritySchemes;
|
|
50
|
+
constructor(config?: OpenApiGeneratorConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Add a controller to be documented
|
|
53
|
+
*/
|
|
54
|
+
addController(controller: Constructor): this;
|
|
55
|
+
/**
|
|
56
|
+
* Add multiple controllers
|
|
57
|
+
*/
|
|
58
|
+
addControllers(controllers: Constructor[]): this;
|
|
59
|
+
/**
|
|
60
|
+
* Add a global security scheme
|
|
61
|
+
*/
|
|
62
|
+
addSecurityScheme(name: string, scheme: OpenApiSecurityScheme): this;
|
|
63
|
+
/**
|
|
64
|
+
* Generate the OpenAPI specification document
|
|
65
|
+
*/
|
|
66
|
+
generate(): OpenApiDocument;
|
|
67
|
+
private getControllerMeta;
|
|
68
|
+
private getControllerRoutes;
|
|
69
|
+
private getControllerTags;
|
|
70
|
+
private isControllerExcluded;
|
|
71
|
+
private isControllerDeprecated;
|
|
72
|
+
private isEndpointExcluded;
|
|
73
|
+
private isEndpointDeprecated;
|
|
74
|
+
private getOperationMetadata;
|
|
75
|
+
private getResponseMetadata;
|
|
76
|
+
private getBodyMetadata;
|
|
77
|
+
private getSwaggerParamMetadata;
|
|
78
|
+
private getQueryMetadata;
|
|
79
|
+
private getHeaderMetadata;
|
|
80
|
+
private getSecurityMetadata;
|
|
81
|
+
private getMethodTags;
|
|
82
|
+
private getHttpStatusCode;
|
|
83
|
+
private getCoreParams;
|
|
84
|
+
private normalizePath;
|
|
85
|
+
private buildOperation;
|
|
86
|
+
private buildParameters;
|
|
87
|
+
private extractPathParams;
|
|
88
|
+
private buildRequestBody;
|
|
89
|
+
private buildResponses;
|
|
90
|
+
private getDefaultStatusDescription;
|
|
91
|
+
private buildSecuritySchemes;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a new OpenAPI generator instance
|
|
95
|
+
*/
|
|
96
|
+
export declare function createOpenApiGenerator(config?: Partial<SwaggerConfig>): OpenApiGenerator;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/openapi/generator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AA4B1B,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAIf,qBAAqB,EACrB,iBAAiB,EAQlB,MAAM,aAAa,CAAC;AAMrB,KAAK,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,GAA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