-
-
Notifications
You must be signed in to change notification settings - Fork 219
test validation of keywords which expect integers when their value has a decimal #429
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
Conversation
Seems reasonable. |
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.
Why just “minItems”? Should we add these tests for all integer-requiring keywords?
c1bbe1f
to
788490b
Compare
@ssilverman see the description
(about to change as I push this out of draft though) |
it appears this change has caught the sanity checker out on the question of whether 1.0 is an integer.
|
That's correctly failing, the test isn't valid on draft4 (where indeed 1.0 is not an integer and it must be). |
788490b
to
8feade0
Compare
removed tests from drafts 3 and 4 |
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.
LGTM
core 4.2.1 is describing the data model for the INSTANCE, not the schema.
https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.6.3 Core doesn't say anything else about zero fractional parts.
https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.1.1 Further...
https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2.1
https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4.2 The validation spec DOES define different requirements for different keywords explicityly, and that is a "MUST". |
I'm not sure if you're saying this PR is incorrect, or adding clarification. my interpretation of the spec, including what you've pointed to, is that 1.0 is an integer. is there a separate data model for schemas? schemas being instances themselves, of the metaschema. the metaschema says these keywords are |
hit the wrong button ... |
I'm not convinced this PR is valid, but I'm willing to be convinced (hence this wasn't a review). As soon as a schema becomes an instance, it's then an instance and not a schema, and so follows the data model of an instance (which makes no distinction with 0 fractional parts). My take on this is:
This could result in a schema being valid according to the meta-schema, but not according to an implementation, because the schema has a 0 fractional part where an interger was expected. |
the fact that the language is a SHOULD NOT instead of a MUST NOT in core 6.3 "integer JSON numbers SHOULD NOT be encoded with a fractional part" seems to indicate that it is allowed, even if not preferred. with the only other definition/clarification of 'integer' in the spec (on the instance data model) stating that it allows a 0 fractional part, and nothing indicating an integer should mean something different in a schema than an instance, it seems reasonable to me to expect it to be allowed. given that the spec explicitly changed from previous drafts disallowing integers a zero fractional part in the instance data model, I think if it were intended that an integer in a schema should mean something different, that language would have been added. |
Right, I'm not saying it IS NOT allowed, but more that it isn't REQUIRED, and so should not be in the default required tests.
That isn't the way specifications work. We don't actually define an "interger" type for schemas, only instances. I don't have any problem adding these tests, but they MUST be optional. |
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.
Because the specification only defines that number and integers with zero fractional in terms of instance data model and evaluation, not schema processing, these tests need to be optional, and not required.
given core 6.3, it seems like a stretch to call this optional. if integers in schemas are allowed by "SHOULD NOT be encoded with a fractional part" to have that fractional part, validators should be expected to support that valid way of expressing a schema. why would the spec change both the instance data model and the general section on mathematical integers to allow (albeit disapprovingly) a fractional part, but not have them be a supported thing for schemas? I know looking at this history "isn't how specs work", but it is context that sure makes it look like supporting this is intended. there's a tiny sliver of plausibility that it's not supposed to be explicitly allowed, in the space between schemas as objects defined by the spec and as instances described by the metaschema. core 6.3 still applies there, but it is a SHOULD NOT, so maybe validators don't have to treat integers in schemas that way. if this is optional, it's not really worth testing. I do believe I've stopped caring about this PR. |
Looks like we need to re-read and evaluate json-schema-org/json-schema-spec#898 6.3 does not related to allowable values in a schema. I do remember something about mathmatical equivalency though, but I don't know where that is now. |
@notEthan I’d still love to see these tests here. If an implementation has had trouble with something, I agree with your approach to write tests for it. What do people think about reopening? |
@notEthan @Relequestual one more comment: I believe these tests test expected behaviour and should be required. |
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.
Schemas are technically instances, and are evaluated with the same data model where 1.0 == 1
. (Otherwise, how could you evaluate a schema against the meta-schema?) This looks correct to me.
I'm not dissageeing with the fact that schemas can be instances if a meta-schema is applied to them. That isn't related to the issue here. The question is, for values which are defined in the meta-schema as integers, should implementations be required to support said values with a zero fractional part? A note at json-schema-org/json-schema-spec#898 (comment) ...
ORIGINALLY the issue we wanted to resolve is recognising that the processing model of JSON Schema should make allowances for where languages would find it very problematic to distinguish between For example, it doesn't ever make sense for
|
To clarify, I'm not saying that we CAN'T make this the case in the spec, but I am saying the 2019-09 draft and the current in progress draft do NOT make this a requirement. |
I'll address the aside first: the only place I see 'number' in the metaschema, including your link highlighting |
I thank you for the time and thought you have put into clarifying this, @Relequestual. I haven't read all the historical discussion of integers in the linked issue, so I'm content to defer to your understanding of all that, and your conclusion that this is optional. it seems to me that logically implementations should have the same rules on a thing like this for schemas and their instances; I think the considerations around encoding and internal representations are very similar or identical for both. I think it might be an improvement if the spec were to align that, but I don't plan to pursue that myself.
I'm hesitant to raise this - I am content to let this rest and don't mean this to be argumentative, so please feel free to leave this without response. but I am confused why the section "general considerations" (6) would not apply to the values in a schema. the rest of section 6 is a mix of considerations which apply to schemas and instances. |
Ah oops, that's me pre-coffee forgetting that THAT keyword is not minContains... Lemme just ---- that... =D |
Reviewing this, I may be inclined to agree. |
@Relequestual do you still object to this PR? I'll rebase if you don't; if you still do you can close it. |
I think by the end here that Ben you're at least coming around to agree with the PR? Essentially the clause that a lot of this PR went back and forth on is about writing out JSON, not reading it -- whether we have the "right" to even govern how to write out JSON aside, for reading, JSON doesn't distinguish between Raise any objection if you have one, but given Austin seems to have thumbs-uped this, and to me it seems correct as well, and your last comment seems to say you're agreeing, going to hit the button later today or tomorrow unless you or someone else speaks up. Sorry this took so long @notEthan. |
8feade0
to
b43da56
Compare
sounds good. I've rebased against main. |
and added draft2020-12 |
Thanks! Can you add it to |
b835669
to
32ec630
Compare
added draft-next, squashed, and another rebase from main |
Thanks! |
to the best of my understanding this should be valid ("the data model makes no distinction between integers and other numbers" -core 4.2.1).
my implementation was incorrectly considering this to be a schema error.