Conversation
Tony133
marked this pull request as ready for review
September 26, 2026 16:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposal:
The ref resolver collects every subschema having an
$idit meets while resolving the route schemas (that is what TypeBoxType.Recursive(..., { $id: 'Node' })produces: an inline schema referencing itself with$ref: 'Node'), and rewrites the references to it as#/definitions/def-N. Howevercomponents.schemas/definitionswere built fromref.definitions()before the routes were processed, so:Missing $ref pointer "#/components/schemas/def-0")$idincluded, which Swagger 2.0 rejects as wellChanges:
referenceInlineDefinitions()(lib/util/definitions.js): after eachref.resolve(), the subschemas matching a collected definition are replaced by{ $ref: '#/definitions/def-N' }and returned. They are matched by$id, not by identity, because the resolver ignores the duplicates of an$id(the same schema used by two routes). Shared schemas, anchors ($id: '#...') and the rootdefinitionsadded by the resolver (already handled byhoistDefinitions) are left alone.resolvereturned byRef()(lib/util/add-hook.js) applies it and accumulates the definitions inref.inlineDefinitions, including the ones nested in a collected definition.ref.inlineDefinitionsto the top-level definitions after the routes loop, through the usualprepareOpenapiSchemas/prepareSwaggerDefinitions.hoistDefinitionsnow treats the definitions known to the resolver as top-level ones: otherwise a shared schema consumed bydef-1was hoisted again asdef-1-def-0.For the schema of the issue,
def-0is now emitted with its recursive$ref, andtreeNodes.itemsbecomes{ $ref: '#/components/schemas/def-0' }. The document validates withswagger-parserin both OpenAPI and Swagger 2.0.An inline
$idschema is now handled exactly like a shared schema referenced with$ref: for instance a querystring property with an$idbecomes a$refparameter, as a$refto a shared schema already does.Note:
$idused as the root of a response still keeps$id: 'todo.com'inline (pre-existing, unrelated to the resolver collection).$idas anaddSchema()one) is left inline, as before.Fixes #865