@@ -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,8 +22,9 @@ 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 { ApiBasicAuth , ApiBearerAuth , ApiCookieAuth , ApiOauth2 } from "../src/decorators/api-security.js" ;
26
28
27
29
test ( "@ApiOperation" , ( ) => {
28
30
class MyController {
@@ -189,3 +191,64 @@ test("@ApiExtraModels", () => {
189
191
190
192
expect ( metadata ) . toEqual ( [ "string" ] ) ;
191
193
} ) ;
194
+
195
+ test ( "@ApiProperty" , ( ) => {
196
+ class User {
197
+ @ApiProperty ( )
198
+ declare declared : string ;
199
+
200
+ @ApiProperty ( )
201
+ // biome-ignore lint/style/noInferrableTypes: required for metadata
202
+ defined : number = 4 ;
203
+
204
+ @ApiProperty ( { type : "string" } )
205
+ explicitType = "test" ;
206
+
207
+ @ApiProperty ( { example : "hey" } )
208
+ get getter ( ) : string {
209
+ return "hello" ;
210
+ }
211
+
212
+ @ApiProperty ( )
213
+ func ( ) : boolean {
214
+ return false ;
215
+ }
216
+ }
217
+
218
+ const metadata = PropertyMetadataStorage . getMetadata ( User . prototype ) ;
219
+
220
+ expect ( metadata . declared ) . toMatchObject ( {
221
+ name : "declared" ,
222
+ required : true ,
223
+ } ) ;
224
+ // @ts -expect-error
225
+ expect ( metadata . declared ?. type ( ) ) . toEqual ( String ) ;
226
+
227
+ expect ( metadata . defined ) . toMatchObject ( {
228
+ name : "defined" ,
229
+ required : true ,
230
+ } ) ;
231
+ // @ts -expect-error
232
+ expect ( metadata . defined ?. type ( ) ) . toEqual ( Number ) ;
233
+
234
+ expect ( metadata . explicitType ) . toMatchObject ( {
235
+ name : "explicitType" ,
236
+ required : true ,
237
+ type : "string" ,
238
+ } ) ;
239
+
240
+ expect ( metadata . getter ) . toMatchObject ( {
241
+ name : "getter" ,
242
+ required : true ,
243
+ example : "hey" ,
244
+ } ) ;
245
+ // @ts -expect-error
246
+ expect ( metadata . getter ?. type ( ) ) . toEqual ( String ) ;
247
+
248
+ expect ( metadata . func ) . toMatchObject ( {
249
+ name : "func" ,
250
+ required : true ,
251
+ } ) ;
252
+ // @ts -expect-error
253
+ expect ( metadata . func ?. type ( ) ) . toEqual ( Boolean ) ;
254
+ } ) ;
0 commit comments