Why should the schema be evaluated? #304
-
I have been trying to understand the logic of this project for some time. So forgive me if I ask too trivial questions...
Some one said:
Maybe I'm wrong, but to me seems like from this specs a lot of things can be extracted... From there comes the main question, why does the schema have to be evaluated or why can't the schema be permissive by default and restricted on demand only where it is needed, using something like NB: I'm aware that older drafts aren't permissive by default, but this matter can be easily solved to be translated to a new permissive draft by adding a requirement for the dependent projects to consider older schemas as having |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Hey there @SorinGFS. Thanks for the questions. I'l have a stab at answering them, and then others will probably chime in with their thoughts. Before I get into the questions, it would be good to understand that JSON Schema is over a decade old at this point and in its 9th iteration. What exists today is the culmination of many authors' efforts and many times more users' feedback.
The meta-schema is "a schema for the schema." It's a special schema that validates a schema. Currently the meta-schema's identifier is also used to describe how an implementation should process the schema, including what keywords the implementation should recognize. Technically, the meta-schema doesn't need to be evaluated. There usually language-specific techniques that a lot of implementations use to ensure a schema is correct without havnig to perform an explicit meta-schema evaluateion. For example, my implementation, JsonSchema.Net, is written in C#, so I get the benefit of a typing system. I literally can't accept anything except a number in Secondly, if a meta-schema is evaluated, it only needs to be evaluated when the schema is loaded, not every time the schema is evaluated. Once loaded and evaluated against the meta-schema, the user can be certain that the schema is valid for the duration of the application. Historically, an implementation is supposed to ignore unknown keywords. Starting with draft 2019-09, when annotations were introduced, it was decided that implementations which support annotations should collect the values of unknown keywords as annotations. I think this aligns with what you're expecting. However, moving forward, we will likely forbid unknown keywords in an effort to make forward-compatability guarantees. You can read more about that in these discussions:
I assume you're talking about the meta-schemas for vocabularies like These were separated because they target a niche audience, they can be difficult to implement fully, and separating them helps modularity. The
Those two keywords evaluate differently for non-integers. Consider these schemas: { "type": "integer", "minimum": 6 }
{ "type": "integer",, "exclusiveMinimum": 5 } These two schemas are effectively equivalent. That is, they'll validate the same sets of data. But let's change the { "type": "number", "minimum": 6 }
{ "type": "number",, "exclusiveMinimum": 5 } Now they validate different sets of data. The second will validate Often, this nuace is necessary. The validation meta-schema actually uses this to define As to why this isn't left to the consuming application, the application expects the schema to do the validation for it. That's its purpose. Since this is a validation that a schema can adequately describe, we support it.
Supporting
In the case of recursive data descriptions, completely resolving those references is impossible. There is an effort to define JSON referencing for non-schema consumers as well that you may be interested in. This repo has a couple proposals that you can read up on.
First, JSON Schema isn't Javascript. It's language agnostic. We can't assume features and conventions of a particular language. The only thing we assume is the JSON data model (we actually support other syntaxes that align with this data model). Secondly, these keywords operate on different data types, and so they do slightly different things.
These keywords do slightly different things. They seem related, but JSON Schema decided that since they target different kinds of data, it's worth separating them. That said, if you wanted, you could create a vocabulary that defines a One of our philosophies is that keywords should be targeted and simple. This is why over the years, we've
"Strict" isn't something that's defined by JSON Schema. Some implementations may define it (most notably AJV), but it's not a concept that comes from here. I'm not sure if that's the perspective you're coming from, but that implementation specifically has made some decisions that do not align with the JSON Schema spec.
We have already decided to move away from IETF and their processes. I'm not sure what is being recommended here.
I'm not sure I understand what you mean by "permissive by default." It seems you're wanting unknown keyword support, but as I mentioned before, that's already supported in the current draft. If you mean something else, can you elaborate? |
Beta Was this translation helpful? Give feedback.
-
JSON Schema 2020-12 and prior is permissive by default. I expect future version to remain permissive by default too. Any implementation which needs a configuration to "enable" "permissive by default" is non-compliant. I know about AJVs strict mode which is enabled by default. This makes some valid schemas throw an error before even running validaiton. |
Beta Was this translation helpful? Give feedback.
JSON Schema 2020-12 and prior is permissive by default. I expect future version to remain permissive by default too.
Any implementation which needs a configuration to "enable" "permissive by default" is non-compliant.
I know about AJVs strict mode which is enabled by default. This makes some valid schemas throw an error before even running validaiton.