@@ -199,7 +199,7 @@ describe('parameters', () => {
199199 } )
200200
201201 it ( 'parses header param from @HeaderParam decorator' , ( ) => {
202- expect ( getHeaderParams ( route ) [ 0 ] ) . toEqual ( {
202+ expect ( getHeaderParams ( route , schemas ) [ 0 ] ) . toEqual ( {
203203 in : 'header' ,
204204 name : 'Authorization' ,
205205 required : true ,
@@ -208,11 +208,76 @@ describe('parameters', () => {
208208 } )
209209
210210 it ( 'parses header param ref from @HeaderParams decorator' , ( ) => {
211- expect ( getHeaderParams ( route ) [ 1 ] ) . toEqual ( {
211+ expect ( getHeaderParams ( route , schemas ) [ 1 ] ) . toEqual ( {
212212 in : 'header' ,
213213 name : 'ListUsersHeaderParams' ,
214214 required : false ,
215215 schema : { $ref : '#/components/schemas/ListUsersHeaderParams' } ,
216216 } )
217217 } )
218+
219+ it ( 'should handle @HeaderParams with types without $ref' , ( ) => {
220+ interface HeadersWithoutRef {
221+ [ key : string ] : string
222+ }
223+
224+ @JsonController ( '/test-no-ref' )
225+ // @ts -ignore: not referenced
226+ class NoRefController {
227+ @Get ( '/' )
228+ testNoRef ( @HeaderParams ( ) _headers : HeadersWithoutRef ) {
229+ return
230+ }
231+ }
232+
233+ const storage = getMetadataArgsStorage ( )
234+ const testRoute = parseRoutes ( storage ) . find ( ( r ) => r . action . method === 'testNoRef' ) !
235+
236+ expect ( ( ) => getHeaderParams ( testRoute , schemas ) ) . not . toThrow ( )
237+ const headers = getHeaderParams ( testRoute , schemas )
238+ expect ( headers ) . toEqual ( [ ] )
239+ } )
240+
241+ it ( 'expands @HeaderParams with properties into individual headers' , ( ) => {
242+ class ExpandableHeaders {
243+ @IsString ( )
244+ Authorization : string
245+
246+ @IsOptional ( )
247+ @IsString ( )
248+ 'X-Request-ID' : string
249+ }
250+
251+ @JsonController ( '/test-expand' )
252+ // @ts -ignore: not referenced
253+ class ExpandController {
254+ @Get ( '/' )
255+ testExpand ( @HeaderParams ( ) _headers : ExpandableHeaders ) {
256+ return
257+ }
258+ }
259+
260+ const storage = getMetadataArgsStorage ( )
261+ const testRoute = parseRoutes ( storage ) . find ( ( r ) => r . action . method === 'testExpand' ) !
262+ const testSchemas = validationMetadatasToSchemas ( {
263+ classTransformerMetadataStorage : defaultMetadataStorage ,
264+ refPointerPrefix : '#/components/schemas/' ,
265+ } )
266+
267+ const headers = getHeaderParams ( testRoute , testSchemas )
268+ expect ( headers ) . toEqual ( [
269+ {
270+ in : 'header' ,
271+ name : 'Authorization' ,
272+ required : true ,
273+ schema : { type : 'string' } ,
274+ } ,
275+ {
276+ in : 'header' ,
277+ name : 'X-Request-ID' ,
278+ required : false ,
279+ schema : { type : 'string' } ,
280+ } ,
281+ ] )
282+ } )
218283} )
0 commit comments