-
-
Notifications
You must be signed in to change notification settings - Fork 886
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
JTDSchemaType null fixes #1456
JTDSchemaType null fixes #1456
Conversation
I might be wrong but I think nullable: false is noop in all cases, so the empty form still should allow all values with or without nullable. @ucarion - is that correct? |
Possibly we should have prohibited nullable in empty form - it adds some confusion... |
@erikbrinkman I believe it is correct - there is the test case that specifically shows that nullable:false should be ignored. |
What do you mean it should be ignored? That Either way it only has one change that actually affects this diff. Currently the diff says that |
|
that is how it is per RFC |
Possibly, ajv in strict mode should log the warning (because I agree - it is counterintuitive). nullable can only be used to make it more general (by allowing null), not to narrow it down (by prohibiting null). |
I see. It does make sense, that |
@erikbrinkman I'll answer your broader question about feedback first, and then the specific question about You can send me feedback in whatever form is most convenient to you, I'm all ears. You can also bring up stuff to the json@ietf.org mailing list, if you want an audience with the JSON bigwigs. The RFC talks a bit more about the JTD experimentation process here: https://www.rfc-editor.org/rfc/rfc8927.html#name-scope-of-experiment At the end of the day, an RFC is an immutable document. But it can be obsoleted by another RFC, and your feedback can inform any follow-on RFC. Moreover, the documentation surrounding JTD can always be improved. One sorta-exception to the "RFCs are immutable" rule: if you find a typo or other error, we can submit an erratum for the RFC to the IETF. They show up here: https://www.rfc-editor.org/errata_search.php?rfc=8927 (currently there aren't any errata) To your specific question about prohibiting I suppose that the fact that this is legal could confuse people: { "type": "string", "nullable": false } into thinking that if you were to remove the |
@erikbrinkman should I close it or are there some fixes that are still needed (and PR needs to be amended)? Thank you! |
@ucarion thanks for addressing both parts. I asked the first just because I didn't want to ask for random comments in a PR for AJV. I'm still not sure I love the syntax, but your arguments are compelling. @epoberezkin this PR still addresses some issues with the way JTD schema was typing null / empty inputs. I just updated this to now allow |
@erikbrinkman it has conflicts now - possibly because I merged #1455 and then reverted? |
@erikbrinkman - sorry to chase - will you check the conflicts out so we can release it? |
Sorry for the delay, it is probably because #1455 was reverted. Have you checked those tests in? I just rebased and it seems fine. Those types generally seemed unrelated, but I could be wrong. As for why typescript isn't inferring the schema type properly, I'm not sure, but I'm looking into it. |
great - thank you! |
What issue does this pull request resolve?
After the last PR, I realized that the way JTDSchemaType handles nulls is wrong. Specifically, an empty schema with nullable doesn't match null, it matches everything. In other words, there's no way to validate a const null field with JTD. In fact, according to the spec
{ nullable: false }
is a valid schema, but it would validate a null value, which makes me think it should be not allowed.What changes did you make?
Moved the empty matching up a "level" in the schema, since it changes the behavior of nullable. I also removed
Record<string, never>
from matching an empty schema, because actually, an empty would validate anything, which would not necessarily be an empty record. As a result I also had to add an extra type check for refs. Omitting the ref type would allow{ ref: string }
to be a valid type since the keys of ref were still a string. As a result, I had to add an extra type guard to ensure they were only string literals.Is there anything that requires more attention while reviewing?
Double check that my ideas about nullable and empty schema are correct. They seem like somewhat of an edge case, but it's important to get right.
Github doesn't seem to like stacked diffs, so it's showing an accepted but unlanded change too. You should just look at the most recent commit.