-
-
Notifications
You must be signed in to change notification settings - Fork 322
Add "$recurse" for extending recursive schemas #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
68db6f3
Add "$recurse" for extending recursive schemas
handrews e9faf6e
Add "$recurse" to the meta-schemas
handrews ba1a498
Add xref for schema document, fix $schema
handrews 13bc158
Add "$recurse" to changelog
handrews da7bdf4
Consolidate sections on reference keywords.
handrews d15f13f
Rework reference sections for new organization
handrews 46252c8
Meta-schema extension is no longer hard
handrews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -571,9 +571,10 @@ | |
</t> | ||
<t> | ||
Authors of extensions to JSON Schema are encouraged to write their own | ||
meta-schemas, which extend the existing meta-schemas using "allOf". | ||
meta-schemas, which MAY extend the existing meta-schemas using "allOf". | ||
This extended meta-schema SHOULD be referenced using the "$schema" keyword, to | ||
allow tools to follow the correct behaviour. | ||
allow tools to follow the correct behaviour. The "$recurse" keyword is | ||
provided to facilitate this usage. | ||
</t> | ||
<t> | ||
Note that the recursive nature of meta-schemas requires re-defining | ||
|
@@ -904,6 +905,86 @@ | |
</section> | ||
</section> | ||
|
||
<section title='Recursive references with "$recurse"'> | ||
<t> | ||
This keyword's value MUST be the boolean literal true. | ||
<cref> | ||
Future drafts may extend the usage with other values. The immediate | ||
use case does not require any targets other than the entry point | ||
root, and a regular fragment URI reference does not provide the | ||
correct semantics. Should other values be added in the future, | ||
it is expected that a boolean true value will remain an alias for | ||
this original use case. | ||
</cref> | ||
</t> | ||
<t> | ||
The presence of this keyword with a boolean true value indicates that, | ||
during processing, it MUST be treated as a reference to the schema document | ||
where processing was initiated. | ||
</t> | ||
<t> | ||
This document, known as the entry point schema, is the schema document that | ||
was initially supplied to the implementation, as opposed to schema documents | ||
that were processed as a result of following a "$ref" reference. Note that | ||
even if processing began at a subschema within a document, the "$recurse" | ||
target MUST be the root of the document. | ||
</t> | ||
<t> | ||
Aside from the dynamic definition of the reference target, a "$recurse" | ||
reference MUST behave identically to a "$ref" reference. | ||
</t> | ||
<figure> | ||
<preamble> | ||
Given the following schemas: | ||
</preamble> | ||
<artwork> | ||
<![CDATA[ | ||
{ | ||
"$id": "https://example.com/base", | ||
"properties": { | ||
"local": { | ||
"$ref": "#", | ||
}, | ||
"recursive": { | ||
"$recurse": true | ||
} | ||
} | ||
} | ||
|
||
{ | ||
"$schema": " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. er... yeah, thanks! |
||
"$id": "https://example.com/extension", | ||
"properties": { | ||
"extended": { | ||
"$ref": "https://example.com/base", | ||
} | ||
} | ||
} | ||
]]> | ||
</artwork> | ||
</figure> | ||
<t> | ||
When an implementation begins processing with the | ||
"https://example.com/base" schema, both the "local" and "recursive" | ||
references resolve to "https://example.com/base". The entry point | ||
schema and the schema being processed are the same. | ||
</t> | ||
<t> | ||
However, when an implementation begins processing with the | ||
"https://example.com/extension" schema, and processes the | ||
"https://example.com/base" schema as a result of following the "$ref" | ||
within the "extended" property, now the entry point schema is | ||
"https://example.com/extension". | ||
</t> | ||
<t> | ||
Therefore the "local" property's reference | ||
still resolves to "https://example.com/base" while the "recursive" property's | ||
reference now resolves to "https://example.com/extension". | ||
This behavior remains the same even if the implementation begins processing | ||
at "https://example.com/extension#/properties/extended". | ||
</t> | ||
</section> | ||
|
||
<section title='Schema Re-Use With "$defs"'> | ||
<t> | ||
The "$defs" keyword provides a standardized location for schema | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vs
The first seems like its saying if we ref into a document at some lower level, it should recurse to THAT level, but the 2nd says it must be the root? Confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the key here is the wording "schema document" which is defined in section 4.3 in both draft-07 and the current HEAD commit. A schema document is a document, not a JSON object. So saying that it MUST be treated as a reference to the schema document where processing was initiated means exactly what the clarification says.
But I'm open to suggestion on how to word it better, preferably without entirely re-stating 4.3. Maybe just an
<xref />
to it? I suspect the complete list of people who understand the distinction without having to look it consists of is @awwright and me.