@@ -9,8 +9,18 @@ type DecoratorFunction = (
9
9
descriptor ?: PropertyDescriptor ,
10
10
) => void ;
11
11
12
+ /**
13
+ * Metadata key to store the property schema
14
+ */
12
15
export const API_PROPERTY = 'api-property' ;
13
16
17
+
18
+ /**
19
+ * Decorator to define API property metadata for a class property.
20
+ *
21
+ * @param property - Optional Swagger schema to define the property metadata.
22
+ * @returns A decorator function that sets the API property metadata.
23
+ */
14
24
export function ApiProperty ( property ?: Swagger . Schema ) : DecoratorFunction {
15
25
return (
16
26
// deno-lint-ignore ban-types
@@ -22,8 +32,23 @@ export function ApiProperty(property?: Swagger.Schema): DecoratorFunction {
22
32
} ;
23
33
}
24
34
35
+
36
+ /**
37
+ * Metadata key to mark a property as optional
38
+ */
25
39
export const OPTIONAL_KEY = 'optional' ;
26
40
41
+ /**
42
+ * Decorator that marks a property or method as optional.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * class Example {
47
+ * @Optional ()
48
+ * optionalProperty?: string;
49
+ * }
50
+ * ```
51
+ */
27
52
export function Optional ( ) : DecoratorFunction {
28
53
return (
29
54
// deno-lint-ignore ban-types
@@ -35,8 +60,17 @@ export function Optional(): DecoratorFunction {
35
60
} ;
36
61
}
37
62
63
+ /**
64
+ * Metadata key to store the returned type of a method
65
+ */
38
66
export const RETURNED_TYPE_KEY = 'returntype' ;
39
67
68
+ /**
69
+ * Decorator to set metadata for the returned type of a method.
70
+ *
71
+ * @param returnedType - The type of the value that the method or property returns.
72
+ * @param isArray - Optional boolean indicating if the returned type is an array.
73
+ */
40
74
export function ReturnedType ( returnedType : unknown , isArray ?: boolean ) : DecoratorFunction {
41
75
return (
42
76
target : Object ,
@@ -55,6 +89,11 @@ export function ReturnedType(returnedType: unknown, isArray?: boolean): Decorato
55
89
} ;
56
90
}
57
91
92
+ /**
93
+ * Decorator to indicate the body type of a request.
94
+ *
95
+ * @param type - The constructor of the type to be used as the body type.
96
+ */
58
97
export function BodyType ( type : Constructor ) : DecoratorFunction {
59
98
return (
60
99
target : Object ,
@@ -65,6 +104,11 @@ export function BodyType(type: Constructor): DecoratorFunction {
65
104
} ;
66
105
}
67
106
107
+ /**
108
+ * Decorator to indicate the query type.
109
+ *
110
+ * @param type - The constructor function of the type to be set as metadata.
111
+ */
68
112
export function QueryType ( type : Constructor ) : DecoratorFunction {
69
113
return (
70
114
target : Object ,
@@ -75,8 +119,29 @@ return (
75
119
} ;
76
120
}
77
121
122
+ /**
123
+ * A constant key used to store or retrieve tags metadata.
124
+ * This key is typically used in decorators to annotate
125
+ * classes or methods with specific tags for documentation.
126
+ */
78
127
export const TAGS_KEY = 'tags' ;
79
128
129
+ /**
130
+ * A decorator function to add an openAPI tag to a class or a method.
131
+ *
132
+ * @param tagName - The name of the tag to be added.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * @Tag ('exampleTag')
137
+ * class ExampleClass {
138
+ * @Tag ('methodTag')
139
+ * exampleMethod() {
140
+ * // method implementation
141
+ * }
142
+ * }
143
+ * ```
144
+ */
80
145
export function Tag ( tagName : string ) : DecoratorFunction {
81
146
return (
82
147
target : Object ,
@@ -91,14 +156,52 @@ return (
91
156
} ;
92
157
}
93
158
159
+ /**
160
+ * A constant key used to store or retrieve api-security metadata.
161
+ */
94
162
export const API_SECURITY = 'api-security' ;
163
+
164
+ /**
165
+ * A constant key used to store or retrieve api-security data metadata.
166
+ */
95
167
export const API_SECURITY_DATA = 'api-security-data' ;
96
168
169
+ /**
170
+ * Indicate that the endpoint use basic authentication security.
171
+ *
172
+ * This function is a shorthand for applying the 'basic' security scheme using the `ApiSecurity` decorator.
173
+ *
174
+ */
97
175
export function ApiBasicAuth ( ) : DecoratorFunction { return ApiSecurity ( 'basic' ) }
176
+ /**
177
+ * Indicate that the endpoint use api bearer auth security.
178
+ *
179
+ * This function is a shorthand for applying the 'bearer' security scheme using the `ApiSecurity` decorator.
180
+ *
181
+ */
98
182
export function ApiBearerAuth ( ) : DecoratorFunction { return ApiSecurity ( 'bearer' ) }
183
+ /**
184
+ * Indicate that the endpoint use cookie security.
185
+ *
186
+ * This function is a shorthand for applying the 'cookie' security scheme using the `ApiSecurity` decorator.
187
+ *
188
+ */
99
189
export function ApiCookieAuth ( ) : DecoratorFunction { return ApiSecurity ( 'cookie' ) }
190
+ /**
191
+ * Indicate that the endpoint use oauth2 security.
192
+ *
193
+ * This function is a shorthand for applying the 'oauth2' security scheme using the `ApiSecurity` decorator.
194
+ *
195
+ */
100
196
export function ApiOAuth2 ( data : string [ ] ) : DecoratorFunction { return ApiSecurity ( 'oauth2' , data ) }
101
197
198
+ /**
199
+ * Decorator that indicate that an endpoint use a security mechanism.
200
+ *
201
+ * @param name - The name of the security scheme.
202
+ * @param data - An optional array of strings representing the security requirements.
203
+ *
204
+ */
102
205
export function ApiSecurity ( name : string , data : string [ ] = [ ] ) : DecoratorFunction {
103
206
return (
104
207
// deno-lint-ignore ban-types
0 commit comments