@@ -8,11 +8,12 @@ import {
88 ApiHeader ,
99 ApiOperation ,
1010 ApiParam ,
11+ ApiProperty ,
1112 ApiQuery ,
1213 ApiResponse ,
1314 ApiSecurity ,
1415 ApiTags ,
15- } from "../src/decorators" ;
16+ } from "../src/decorators/index.js " ;
1617import {
1718 ExcludeMetadataStorage ,
1819 ExtraModelsMetadataStorage ,
@@ -21,8 +22,9 @@ import {
2122 OperationParameterMetadataStorage ,
2223 OperationResponseMetadataStorage ,
2324 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" ;
2628
2729test ( "@ApiOperation" , ( ) => {
2830 class MyController {
@@ -189,3 +191,64 @@ test("@ApiExtraModels", () => {
189191
190192 expect ( metadata ) . toEqual ( [ "string" ] ) ;
191193} ) ;
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