Open ollyhensby opened 1 month ago
The JSON schema spec was updated to allow sibling keys alongside $ref keys so it is no longer required to wrap the $ref key in a allOf array with a single $ref element.
This is indeed why it doesn't work here by default and has caused much confusion. The jsonref spec says All other properties of an object containing a $ref key are ignored.
That means that the thing you are trying to reference is ignored in your first case by virtue of being another property in the object with the $ref. Jsonschema no longer uses the jsonref spec, and instead defines $refs themselves now, and apparently took that language about ignoring other sibling keys out of their spec.
The good thing is, we already added an option to this library to ignore that part of the jsonref spec. It should do what you want by using the merge_props=True
argument to replace_refs
.
Thank you for the explanation @gazpachoking! Using merge_props=True
has resolved this issue for us.
Is there any motivation to set merge_props=True
as the default setting since the jsonschema now no longer uses the jsonref spec?
Issue I've defined the following schema with a single
$ref
element andresolve_refs
is failing to resolve it:I get the following traceback:
If I replace the reference section with:
the
replace_refs
works as expected.Context
I noticed this issue through the use of pydantic when using their
model_json_schema
method. Inpydantic==2.8
the JSON schema returned from a model returns with theallOf
, whereas inpydantic==2.9
the model returns without theallOf
.I am no expert in JSON schema but from what they've said I think it's related to this: https://github.com/pydantic/pydantic/pull/10029#issue-2444644197
User
dpeachey
says thatThe JSON schema spec was updated to allow sibling keys alongside $ref keys so it is no longer required to wrap the $ref key in a allOf array with a single $ref element.
This is mentioned in the JSON schema spec here: https://json-schema.org/draft/2020-12/json-schema-core#appendix-G-2.6.1.10
Any help with this issue is much appreciated!