-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
Final review and corrections for $dynamicAnchor
/$dynamicRef
before release
#1030
Comments
Here's an example of a non-recursive use for Hyper-schemers will recognize this pattern. Let's say I have several resources and for each resource, I want two schemas: one for a single instance and another for a list of instances. The list of instances follows a common pattern that looks something like this. {
"$id": "https://json-schema.hyperjump.io/schema/list",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"properties": {
"list": { "type": "array" },
"nextPage": { "type": "integer" },
"previousPage": { "type": "integer" },
"perPage": { "type": "integer" },
"page": { "type": "integer" }
}
} I can then compose this schema with another to create a list schema for a specific resource. {
"$id": "https://json-schema.hyperjump.io/schema/foo-list",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$ref": "/schema/list",
"properties": {
"list": {
"items": { "$ref": "/schema/foo" }
}
}
} That's not too bad, but it does couple this schema with the "list" property name. If I decided I want to change that name to "itemList", I would have to change not only "/schema/list", but also every schema I composed it with. That's where You can put the following example in https://json-schema.hyperjump.io and see it in action. (Note: you have to use draft "future" to specify the new unreleased draft) {
"$id": "https://json-schema.hyperjump.io/schema/foo-list",
"$schema": "https://json-schema.org/draft/future/schema",
"$ref": "/schema/list",
"$defs": {
"foo": {
"$dynamicAnchor": "list",
"$ref": "/schema/foo"
}
}
} {
"$id": "https://json-schema.hyperjump.io/schema/list",
"$schema": "https://json-schema.org/draft/future/schema",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": { "$dynamicRef": "#list" }
},
"nextPage": { "type": "integer" },
"previousPage": { "type": "integer" },
"perPage": { "type": "integer" },
"page": { "type": "integer" }
}
} {
"$id": "https://json-schema.hyperjump.io/schema/foo",
"$schema": "https://json-schema.org/draft/future/schema",
"type": "object",
"properties": {
"foo": { "type": "string" }
}
} It's a little awkward, but it's decoupled. I can now change whatever I want about the According to the way the spec is written, "$defs": {
"list": { "$dynamicAnchor": "list" }
} But that's just putting the |
I think I figured out why the two-step resolution stuff exists. If an implementation resolves |
I find this part of the spec VERY hard to reason about.
Ah, yeah, I see that.
I think I'd totally missed this also. And in response to your comment just above... I have a feeling we ended up trying to make it simple and with a specific limited use case, and wait and see if and how people use it and later WANT to use it. |
emoving from milestone for reasons as detailed: #1033 (comment) |
I'm going to close this and re-file it as a change proposal for the next draft. |
I'm doing a final review of
$dynamicAnchor
/$dynamicRef
before release and I think there are a couple places that need some attention.https://github.com/json-schema-org/json-schema-spec/blob/master/jsonschema-core.xml#L658-L670
This cref doesn't make sense any more.
$dynamicAnchor
is not "only allowed in the root schema" as it was with$recursiveRef
. I think that makes this cref moot and can just be removed, but I'd like a second opinion.https://github.com/json-schema-org/json-schema-spec/blob/master/jsonschema-core.xml#L3597
"$dynamicAnchor": node
=>$dynamicAnchor": "node"
https://github.com/json-schema-org/json-schema-spec/blob/master/jsonschema-core.xml#L1487-L1501
First of all, I apologize profusely for not noticing and bringing this up until only a few days before planed release.
Requiring the "initially resolved starting point" to include a
$dynamicAnchor
doesn't make sense for non-recursive use-cases. I'll follow up with an example later. There's a cref describing why this requirement was included, but it doesn't make sense to me.I don't see how an
$anchor
can affect dynamic scope resolution. It certainly can't the way I've implemented this feature, so I'm not sure what I'm missing. If someone can explain the potential problem here, maybe we can compare the pros and cons of dropping this requirement so non-recursive use-cases make sense.I also wouldn't mind an explanation of why the two step resolution process exists. This all seems more complicated than it needs to be. I don't see why it's not simply:
$ref
resolves against lexical scope and$dynamicRef
resolves against dynamic scope where the dynamic scope is marked by the outermost$dynamicAnchor
that matches the$dynamicRef
. I thought that's what we had decided on, and again I apologize for not noticing until now that this had gotten written up differently than I thought it had.The text was updated successfully, but these errors were encountered: