@@ -8,11 +8,12 @@ import {
8
8
ApiHeader ,
9
9
ApiOperation ,
10
10
ApiParam ,
11
+ ApiProperty ,
11
12
ApiQuery ,
12
13
ApiResponse ,
13
14
ApiSecurity ,
14
15
ApiTags ,
15
- } from "../src/decorators" ;
16
+ } from "../src/decorators/index.js " ;
16
17
import {
17
18
ExcludeMetadataStorage ,
18
19
ExtraModelsMetadataStorage ,
@@ -21,16 +22,25 @@ import {
21
22
OperationParameterMetadataStorage ,
22
23
OperationResponseMetadataStorage ,
23
24
OperationSecurityMetadataStorage ,
24
- } from "../src/metadata" ;
25
- import { ApiBasicAuth , ApiBearerAuth , ApiCookieAuth , ApiOauth2 } from "../src/decorators/api-security" ;
25
+ PropertyMetadataStorage ,
26
+ } from "../src/metadata/index.js" ;
27
+ import {
28
+ ApiBasicAuth ,
29
+ ApiBearerAuth ,
30
+ ApiCookieAuth ,
31
+ ApiOauth2 ,
32
+ } from "../src/decorators/api-security.js" ;
26
33
27
34
test ( "@ApiOperation" , ( ) => {
28
35
class MyController {
29
36
@ApiOperation ( { summary : "Hello" , path : "/test" , methods : [ "get" ] } )
30
37
operation ( ) { }
31
38
}
32
39
33
- const metadata = OperationMetadataStorage . getMetadata ( MyController . prototype , "operation" ) ;
40
+ const metadata = OperationMetadataStorage . getMetadata (
41
+ MyController . prototype ,
42
+ "operation" ,
43
+ ) ;
34
44
35
45
expect ( metadata ) . toEqual ( {
36
46
summary : "Hello" ,
@@ -45,7 +55,10 @@ test("@ApiBody", () => {
45
55
operation ( ) { }
46
56
}
47
57
48
- const metadata = OperationBodyMetadataStorage . getMetadata ( MyController . prototype , "operation" ) ;
58
+ const metadata = OperationBodyMetadataStorage . getMetadata (
59
+ MyController . prototype ,
60
+ "operation" ,
61
+ ) ;
49
62
50
63
expect ( metadata ) . toEqual ( {
51
64
type : "string" ,
@@ -60,7 +73,11 @@ test("@ApiParam", () => {
60
73
operation ( ) { }
61
74
}
62
75
63
- const metadata = OperationParameterMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
76
+ const metadata = OperationParameterMetadataStorage . getMetadata (
77
+ MyController . prototype ,
78
+ "operation" ,
79
+ true ,
80
+ ) ;
64
81
65
82
expect ( metadata ) . toEqual ( [
66
83
{ in : "path" , name : "test" } ,
@@ -75,7 +92,11 @@ test("@ApiHeader", () => {
75
92
operation ( ) { }
76
93
}
77
94
78
- const metadata = OperationParameterMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
95
+ const metadata = OperationParameterMetadataStorage . getMetadata (
96
+ MyController . prototype ,
97
+ "operation" ,
98
+ true ,
99
+ ) ;
79
100
80
101
expect ( metadata ) . toEqual ( [
81
102
{ in : "header" , name : "test" } ,
@@ -90,7 +111,11 @@ test("@ApiCookie", () => {
90
111
operation ( ) { }
91
112
}
92
113
93
- const metadata = OperationParameterMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
114
+ const metadata = OperationParameterMetadataStorage . getMetadata (
115
+ MyController . prototype ,
116
+ "operation" ,
117
+ true ,
118
+ ) ;
94
119
95
120
expect ( metadata ) . toEqual ( [
96
121
{ in : "cookie" , name : "test" } ,
@@ -105,7 +130,11 @@ test("@ApiQuery", () => {
105
130
operation ( ) { }
106
131
}
107
132
108
- const metadata = OperationParameterMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
133
+ const metadata = OperationParameterMetadataStorage . getMetadata (
134
+ MyController . prototype ,
135
+ "operation" ,
136
+ true ,
137
+ ) ;
109
138
110
139
expect ( metadata ) . toEqual ( [
111
140
{ in : "query" , name : "test" } ,
@@ -120,7 +149,11 @@ test("@ApiResponse", () => {
120
149
operation ( ) { }
121
150
}
122
151
123
- const metadata = OperationResponseMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
152
+ const metadata = OperationResponseMetadataStorage . getMetadata (
153
+ MyController . prototype ,
154
+ "operation" ,
155
+ true ,
156
+ ) ;
124
157
125
158
expect ( metadata ) . toEqual ( {
126
159
default : { status : "default" , mediaType : "text/html" , type : "string" } ,
@@ -135,7 +168,11 @@ test("@ApiTags", () => {
135
168
operation ( ) { }
136
169
}
137
170
138
- const metadata = OperationMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
171
+ const metadata = OperationMetadataStorage . getMetadata (
172
+ MyController . prototype ,
173
+ "operation" ,
174
+ true ,
175
+ ) ;
139
176
140
177
expect ( metadata . tags ) . toEqual ( [ "Root" , "Hello" , "World" ] ) ;
141
178
} ) ;
@@ -150,7 +187,11 @@ test("@ApiSecurity", () => {
150
187
operation ( ) { }
151
188
}
152
189
153
- const metadata = OperationSecurityMetadataStorage . getMetadata ( MyController . prototype , "operation" , true ) ;
190
+ const metadata = OperationSecurityMetadataStorage . getMetadata (
191
+ MyController . prototype ,
192
+ "operation" ,
193
+ true ,
194
+ ) ;
154
195
155
196
expect ( metadata ) . toEqual ( {
156
197
custom : [ ] ,
@@ -175,7 +216,10 @@ test("@ApiExcludeOperation", () => {
175
216
operation ( ) { }
176
217
}
177
218
178
- const metadata = ExcludeMetadataStorage . getMetadata ( MyController . prototype , "operation" ) ;
219
+ const metadata = ExcludeMetadataStorage . getMetadata (
220
+ MyController . prototype ,
221
+ "operation" ,
222
+ ) ;
179
223
expect ( metadata ) . toBe ( true ) ;
180
224
} ) ;
181
225
@@ -189,3 +233,64 @@ test("@ApiExtraModels", () => {
189
233
190
234
expect ( metadata ) . toEqual ( [ "string" ] ) ;
191
235
} ) ;
236
+
237
+ test ( "@ApiProperty" , ( ) => {
238
+ class User {
239
+ @ApiProperty ( )
240
+ declare declared : string ;
241
+
242
+ @ApiProperty ( )
243
+ // biome-ignore lint/style/noInferrableTypes: required for metadata
244
+ defined : number = 4 ;
245
+
246
+ @ApiProperty ( { type : "string" } )
247
+ explicitType = "test" ;
248
+
249
+ @ApiProperty ( { example : "hey" } )
250
+ get getter ( ) : string {
251
+ return "hello" ;
252
+ }
253
+
254
+ @ApiProperty ( )
255
+ func ( ) : boolean {
256
+ return false ;
257
+ }
258
+ }
259
+
260
+ const metadata = PropertyMetadataStorage . getMetadata ( User . prototype ) ;
261
+
262
+ expect ( metadata . declared ) . toMatchObject ( {
263
+ name : "declared" ,
264
+ required : true ,
265
+ } ) ;
266
+ // @ts -expect-error
267
+ expect ( metadata . declared ?. type ( ) ) . toEqual ( String ) ;
268
+
269
+ expect ( metadata . defined ) . toMatchObject ( {
270
+ name : "defined" ,
271
+ required : true ,
272
+ } ) ;
273
+ // @ts -expect-error
274
+ expect ( metadata . defined ?. type ( ) ) . toEqual ( Number ) ;
275
+
276
+ expect ( metadata . explicitType ) . toMatchObject ( {
277
+ name : "explicitType" ,
278
+ required : true ,
279
+ type : "string" ,
280
+ } ) ;
281
+
282
+ expect ( metadata . getter ) . toMatchObject ( {
283
+ name : "getter" ,
284
+ required : true ,
285
+ example : "hey" ,
286
+ } ) ;
287
+ // @ts -expect-error
288
+ expect ( metadata . getter ?. type ( ) ) . toEqual ( String ) ;
289
+
290
+ expect ( metadata . func ) . toMatchObject ( {
291
+ name : "func" ,
292
+ required : true ,
293
+ } ) ;
294
+ // @ts -expect-error
295
+ expect ( metadata . func ?. type ( ) ) . toEqual ( Boolean ) ;
296
+ } ) ;
0 commit comments