Skip to content
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

Allow different $schema values in same document if different resources #850

Closed
handrews opened this issue Feb 5, 2020 · 3 comments · Fixed by #914
Closed

Allow different $schema values in same document if different resources #850

handrews opened this issue Feb 5, 2020 · 3 comments · Fixed by #914
Assignees
Labels

Comments

@handrews
Copy link
Contributor

handrews commented Feb 5, 2020

Currently, you can put $schema in a resource root object, which means you can have multiple $schema keywords in the same document. Currently we say that schema authors SHOULD only have $schema in the document root, and we say that if multiple resources in the same schema have different $schema values, the meta-schema is undefined. There's a CREF giving some of the backstory.

Before the schema resource concept was introduced, and tied to the updated $id keyword, there was concern about allowing $schema to be dropped into any random schema object.

But now we have two types of schema objects: schema resource root objects, and schema objects within a resource. The document root object is a special case of the schema root object.

Schema resource roots are easily detected ($id means its a schema resource root), and we already do special processing of them. Allowing the $schema to change there makes sense, as we want schema resources to behave the same whether they are linked with $ref (in which case you can definitely change $schema) or not (which is currently undefined).

I think we should go ahead and define this behavior. It also fits in with #849 (clarifying and consolidating the schema loading process), where we will talk about how to load embedded schema resources within a single document.

@Relequestual
Copy link
Member

Splitting up $id into two use cases ( now with $anchor) was a great idea.
Yup. I'm all for the above!

@karenetheridge
Copy link
Member

It should also be possible (thank you $recursiveRef!) to make this restriction explicit in the metaschema with a rule "if the $id property appears, $schema is allowed; else, $schema is prohibited".

@handrews
Copy link
Contributor Author

@karenetheridge we've generally avoided enforcing those things in the meta-schemas because they are technically not forbidden. They just have "undefined" behavior.

Due to $recursiveRef and $recursiveAnchor, though, you can write your own strict meta-schema with the same standard vocabularies to enforce whatever makes sense to you.

I agree that this is a gray area, (as opposed to people wanting us to, say, forbid properties unless type is object), and I could be convinced that we should enforce resource roots vs subschemas in the meta-schema. But I'm not yet convinced of that. I kind of want to see what people do in practice with making custom meta-schemas now that we've made that easier and more effective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants