@@ -305,13 +305,19 @@ function resolveCommonParams (container, parameters, schema, ref, sharedSchemas,
305305
306306// Keys to references could be different than the name of the $ref,
307307// 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- } )
308+ function findReferenceDescription ( rawSchema , ref ) {
309+ // FIXME: Resolve directly?
310+ const resolvedReference = ref . resolve ( rawSchema , { externalSchemas : [ ref . definitions ( ) . definitions ] } )
311+
312+ // Ref has format `#/definitions/id`
313+ const schemaId = resolvedReference ?. $ref ?. split ( '/' ) [ 2 ]
313314
314- return definitions [ schemaKey ] ?? { }
315+ if ( schemaId === undefined ) {
316+ return undefined
317+ }
318+
319+ const schema = resolvedReference . definitions [ schemaId ]
320+ return schema ?. description
315321}
316322
317323// https://swagger.io/docs/specification/describing-responses/
@@ -324,7 +330,6 @@ function resolveResponse (fastifyResponseJson, produces, ref) {
324330 const responsesContainer = { }
325331
326332 const statusCodes = Object . keys ( fastifyResponseJson )
327- const definitions = ref . definitions ( ) . definitions
328333
329334 statusCodes . forEach ( statusCode => {
330335 const rawJsonSchema = fastifyResponseJson [ statusCode ]
@@ -338,12 +343,10 @@ function resolveResponse (fastifyResponseJson, produces, ref) {
338343 statusCode = statusCode . toUpperCase ( )
339344 }
340345
341- const referenceJsonSchema = findReference ( definitions , rawJsonSchema . $ref )
342-
343346 const response = {
344347 description : resolved [ xResponseDescription ] ||
345348 rawJsonSchema . description ||
346- referenceJsonSchema . description ||
349+ findReferenceDescription ( rawJsonSchema , ref ) ||
347350 'Default Response'
348351 }
349352
0 commit comments