@@ -308,6 +308,49 @@ test('uses examples if has property required in body', async (t) => {
308308 t . assert . deepStrictEqual ( schema . parameters [ 0 ] . in , 'query' )
309309} )
310310
311+ test ( 'renders required query parameter when property is a $ref' , async ( t ) => {
312+ const fastify = Fastify ( )
313+ await fastify . register ( fastifySwagger , { openapi : { } } )
314+
315+ fastify . addSchema ( {
316+ $id : 'CoringUploadTypeApiModel' ,
317+ type : 'string' ,
318+ enum : [ 'health_safety' , 'coring' ]
319+ } )
320+
321+ fastify . get ( '/some-route' , {
322+ schema : {
323+ query : {
324+ type : 'object' ,
325+ required : [ 'thing' ] ,
326+ properties : {
327+ thing : { $ref : 'CoringUploadTypeApiModel' } ,
328+ other : { type : 'string' }
329+ }
330+ } ,
331+ response : {
332+ 200 : {
333+ type : 'object' ,
334+ properties : {
335+ hello : { type : 'string' }
336+ }
337+ }
338+ }
339+ }
340+ } , ( ) => ( { hello : 'world' } ) )
341+
342+ await fastify . ready ( )
343+
344+ const openapiObject = fastify . swagger ( )
345+ await Swagger . validate ( openapiObject )
346+
347+ const thingQueryParam = openapiObject . paths [ '/some-route' ] . get . parameters . find ( parameter => parameter . name === 'thing' )
348+ const otherQueryParam = openapiObject . paths [ '/some-route' ] . get . parameters . find ( parameter => parameter . name === 'other' )
349+
350+ t . assert . strictEqual ( thingQueryParam . required , true )
351+ t . assert . strictEqual ( otherQueryParam . required , false )
352+ } )
353+
311354test ( 'renders $ref schema with enum in headers' , async ( t ) => {
312355 const fastify = Fastify ( )
313356 await fastify . register ( fastifySwagger , { openapi : { } } )
0 commit comments