Skip to content

fix: do not read a $ref inside default, const, enum or examples as a reference - #54

Open
nigrosimone wants to merge 1 commit into
fastify:mainfrom
nigrosimone:skip-data-keywords
Open

nigrosimone wants to merge 1 commit into
fastify:mainfrom
nigrosimone:skip-data-keywords

Conversation

@nigrosimone

Copy link
Copy Markdown

addSchema walks every object in a schema and records each $ref it meets, so a $ref key inside a default, const, enum or examples value, where it is a property of the instance and not a reference, is recorded as one. getSchemaDependencies then throws Cannot resolve ref for it, and getDerefSchema walks into the data too. It came up in fast-json-stringify: a schema with default: { $ref: '...' } on one property and anyOf on another cannot be built.

The fix skips those four keywords in both walks.

The added test puts a $ref under each of the four and checks the refs, the dependencies and the deref schema: it fails on main and passes here.

@nigrosimone
nigrosimone marked this pull request as ready for review September 13, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant