-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Example of $recursiveRoot and $recursiveRef #605
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-08/hyper-operations-FAKE#", | ||
"$id": "http://json-schema.org/draft-08/hyper-operations-FAKE", | ||
"$recursiveRoot": true, | ||
|
||
"title": "FAKE DEMO JSON Hypermedia Operations FOR RECURSION EXAMPLE", | ||
"$ref": "http://json-schema.org/draft-08/hyper-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. This is a regular 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. Did we resolve the issue of 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. Looks like there's an informal decision in #523. I guess you're assuming that? 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. Yes, there's also PR #585 which will hopefully start moving again soon. I've been acting as if it's done because that's definitely what draft-08 will look like. (I'm not sure what you mean by "informal decision", do we even have formal decisions here? Other than merging PRs?) |
||
"properties": { | ||
"base": { | ||
"type": "string", | ||
"format": "uri-template" | ||
}, | ||
"links": { | ||
"items": { | ||
"operations": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"someKindOfSchema": { "$recursiveRef": "#" } | ||
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. This |
||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"href": "{+%24id}" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,19 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-08/hyper-schema#", | ||
"$id": "http://json-schema.org/draft-08/hyper-schema#", | ||
"$id": "http://json-schema.org/draft-08/hyper-schema", | ||
"$recursiveRoot": true, | ||
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. Hyper-schema is a recursive meta-schema. It extends the core/validation recursive meta-schema, and is in turn extended by the hyper-operations meta-schema (which is fake and made up for this example). It also references links.json, which is the stand-alone LDO schema, which refers back to this meta-schema. If hyper-schema.json is the entry point schema document, then this A more complex example is if links.json is the entry point schema. That is not a recursive schema, so it does not set |
||
|
||
"title": "JSON Hyper-Schema", | ||
"$defs": { | ||
"schemaArray": { | ||
"allOf": [ | ||
{ "$ref": "http://json-schema.org/draft-08/schema#/$defs/schemaArray" }, | ||
{ | ||
"items": { "$ref": "#" } | ||
} | ||
] | ||
} | ||
}, | ||
"allOf": [ { "$ref": "http://json-schema.org/draft-08/schema#" } ], | ||
"$ref": "http://json-schema.org/draft-08/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. As with hyper-operations.json referencing this schema, we use |
||
"properties": { | ||
"additionalItems": { "$ref": "#" }, | ||
"additionalProperties": { "$ref": "#"}, | ||
"dependencies": { | ||
"additionalProperties": { | ||
"anyOf": [ | ||
{ "$ref": "#" }, | ||
{ "type": "array" } | ||
] | ||
} | ||
}, | ||
"items": { | ||
"anyOf": [ | ||
{ "$ref": "#" }, | ||
{ "$ref": "#/$defs/schemaArray" } | ||
] | ||
}, | ||
"$defs": { | ||
"additionalProperties": { "$ref": "#" } | ||
}, | ||
"definitions": { | ||
"$comment": "Renamed to $defs, but retained here to ensure compatibility", | ||
"additionalProperties": { "$ref": "#" } | ||
}, | ||
"patternProperties": { | ||
"additionalProperties": { "$ref": "#" } | ||
}, | ||
"properties": { | ||
"additionalProperties": { "$ref": "#" } | ||
}, | ||
"if": {"$ref": "#"}, | ||
"then": {"$ref": "#"}, | ||
"else": {"$ref": "#"}, | ||
"allOf": { "$ref": "#/$defs/schemaArray" }, | ||
"anyOf": { "$ref": "#/$defs/schemaArray" }, | ||
"oneOf": { "$ref": "#/$defs/schemaArray" }, | ||
"not": { "$ref": "#" }, | ||
"contains": { "$ref": "#" }, | ||
"propertyNames": { "$ref": "#" }, | ||
|
||
"base": { | ||
"type": "string", | ||
"format": "uri-template" | ||
}, | ||
"links": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "http://json-schema.org/draft-08/links#" | ||
"$ref": "http://json-schema.org/draft-08/links" | ||
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. The reference to links.json is a regular However, since at this point we have already set |
||
} | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-08/hyper-schema#", | ||
"$id": "http://json-schema.org/draft-08/links#", | ||
"$id": "http://json-schema.org/draft-08/links", | ||
"title": "Link Description Object", | ||
"allOf": [ | ||
{ "required": [ "rel", "href" ] }, | ||
|
@@ -29,7 +29,7 @@ | |
"format": "uri-template" | ||
}, | ||
"hrefSchema": { | ||
"$ref": "http://json-schema.org/draft-08/hyper-schema#" | ||
"$recursiveRef": "http://json-schema.org/draft-08/hyper-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. When using links.json as a standalone schema, it is the entry point schema, and for the initial evaluation it does not matter whether this is a When links.json is referenced from hyper-schema.json (with hyper-schema.json as the entry point), then we have seen as When links.json is referenced from hyper-schema.json, when the entry point was hyper-operations.json, then the These behaviors show how the same links.json can be used on its own (referring to hyper-schema.json which extends schema.json) and as a component within hyper-schema.json (or an extension of it, such as hyper-operations.json). |
||
}, | ||
"templatePointers": { | ||
"type": "object", | ||
|
@@ -55,21 +55,21 @@ | |
"type": "string" | ||
}, | ||
"targetSchema": { | ||
"$ref": "http://json-schema.org/draft-08/hyper-schema#" | ||
"$recursiveRef": "http://json-schema.org/draft-08/hyper-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. Since there is no This still works fine when we start from links.json,
|
||
}, | ||
"targetMediaType": { | ||
"type": "string" | ||
}, | ||
"targetHints": { }, | ||
"headerSchema": { | ||
"$ref": "http://json-schema.org/draft-08/hyper-schema#" | ||
"$recursiveRef": "http://json-schema.org/draft-08/hyper-schema" | ||
}, | ||
"submissionMediaType": { | ||
"type": "string", | ||
"default": "application/json" | ||
}, | ||
"submissionSchema": { | ||
"$ref": "http://json-schema.org/draft-08/hyper-schema#" | ||
"$recursiveRef": "http://json-schema.org/draft-08/hyper-schema" | ||
}, | ||
"$comment": { | ||
"type": "string" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-08/schema#", | ||
"$id": "http://json-schema.org/draft-08/schema#", | ||
|
||
"title": "Core schema meta-schema", | ||
"$defs": { | ||
"schemaArray": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { "$ref": "#" } | ||
"items": { "$recursiveRef": "#" } | ||
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. schema.json does not need When used from hyper-schema.json (with either it, links.json, or hyper-operations.json as the entry schema document), a |
||
}, | ||
"nonNegativeInteger": { | ||
"type": "integer", | ||
|
@@ -55,13 +56,13 @@ | |
}, | ||
"$defs": { | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"additionalProperties": { "$recursiveRef": "#" }, | ||
"default": {} | ||
}, | ||
"definitions": { | ||
"$comment": "While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.", | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"additionalProperties": { "$recursiveRef": "#" }, | ||
"default": {} | ||
}, | ||
"title": { | ||
|
@@ -101,10 +102,10 @@ | |
"type": "string", | ||
"format": "regex" | ||
}, | ||
"additionalItems": { "$ref": "#" }, | ||
"additionalItems": { "$recursiveRef": "#" }, | ||
"items": { | ||
"anyOf": [ | ||
{ "$ref": "#" }, | ||
{ "$recursiveRef": "#" }, | ||
{ "$ref": "#/$defs/schemaArray" } | ||
], | ||
"default": true | ||
|
@@ -115,32 +116,37 @@ | |
"type": "boolean", | ||
"default": false | ||
}, | ||
"contains": { "$ref": "#" }, | ||
"contains": { "$recursiveRef": "#" }, | ||
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" }, | ||
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, | ||
"required": { "$ref": "#/$defs/stringArray" }, | ||
"additionalProperties": { "$ref": "#" }, | ||
"additionalProperties": { "$recursiveRef": "#" }, | ||
"properties": { | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"additionalProperties": { "$recursiveRef": "#" }, | ||
"default": {} | ||
}, | ||
"patternProperties": { | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"additionalProperties": { "$recursiveRef": "#" }, | ||
"propertyNames": { "format": "regex" }, | ||
"default": {} | ||
}, | ||
"dependencies": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"anyOf": [ | ||
{ "$ref": "#" }, | ||
{ "$ref": "#/$defs/stringArray" } | ||
] | ||
"$recursiveRef": "#" | ||
} | ||
}, | ||
"propertyNames": { "$ref": "#" }, | ||
"requiredDependencies": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/$defs/stringArray" | ||
} | ||
}, | ||
"propertyNames": { | ||
"additionalProperties": { "$recursiveRef": "#" } | ||
}, | ||
"const": true, | ||
"enum": { | ||
"type": "array", | ||
|
@@ -162,13 +168,13 @@ | |
"format": { "type": "string" }, | ||
"contentMediaType": { "type": "string" }, | ||
"contentEncoding": { "type": "string" }, | ||
"if": {"$ref": "#"}, | ||
"then": {"$ref": "#"}, | ||
"else": {"$ref": "#"}, | ||
"if": { "$recursiveRef": "#" }, | ||
"then": { "$recursiveRef": "#" }, | ||
"else": { "$recursiveRef": "#" }, | ||
"allOf": { "$ref": "#/$defs/schemaArray" }, | ||
"anyOf": { "$ref": "#/$defs/schemaArray" }, | ||
"oneOf": { "$ref": "#/$defs/schemaArray" }, | ||
"not": { "$ref": "#" } | ||
"not": { "$recursiveRef": "#" } | ||
}, | ||
"default": true | ||
} |
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.
This schema extends another recursive schema, and in this PR example, nothing extends it. So it is always the entry point schema when it is used at all.
So here
"$recursiveRoot": true
pins the target of all"$recursiveRef"
s that are encountered.