@@ -303,6 +303,17 @@ function resolveCommonParams (container, parameters, schema, ref, sharedSchemas,
303303 arr . forEach ( swaggerSchema => parameters . push ( swaggerSchema ) )
304304}
305305
306+ // Keys to references could be different than the name of the $ref,
307+ // for example `def-0`
308+ function findReference ( definitions , id ) {
309+ const schemaKey = Object . keys ( definitions ) . find ( key => {
310+ const schema = definitions [ key ]
311+ return schema . $id === id
312+ } )
313+
314+ return definitions [ schemaKey ] ?? { }
315+ }
316+
306317// https://swagger.io/docs/specification/describing-responses/
307318function resolveResponse ( fastifyResponseJson , produces , ref ) {
308319 // if the user does not provided an out schema
@@ -313,6 +324,7 @@ function resolveResponse (fastifyResponseJson, produces, ref) {
313324 const responsesContainer = { }
314325
315326 const statusCodes = Object . keys ( fastifyResponseJson )
327+ const definitions = ref . definitions ( ) . definitions
316328
317329 statusCodes . forEach ( statusCode => {
318330 const rawJsonSchema = fastifyResponseJson [ statusCode ]
@@ -326,8 +338,13 @@ function resolveResponse (fastifyResponseJson, produces, ref) {
326338 statusCode = statusCode . toUpperCase ( )
327339 }
328340
341+ const referenceJsonSchema = findReference ( definitions , rawJsonSchema . $ref )
342+
329343 const response = {
330- description : resolved [ xResponseDescription ] || rawJsonSchema . description || 'Default Response'
344+ description : referenceJsonSchema . description ||
345+ resolved [ xResponseDescription ] ||
346+ rawJsonSchema . description ||
347+ 'Default Response'
331348 }
332349
333350 // add headers when there are any.
0 commit comments