-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
How to interpret schemas that contains not
keyword
#19
Comments
not
keywordnot
keyword
I would love to say that On the other hand, the refactored schemas would produce different annotation results, so if any of this process is defined based on annotations (which seems likely), you could argue that those schemas are not equivalent and we don't need to find a way to make the code output equivalent. |
I can only see that the refactored schema will always give the same output as the schema with |
Annotations are a JSON Schema concept where information is gathered about an instances as it is validated. If a schema fails validation, it produces no annotations. Here's an example of what an annotations result might look like based on the first example given the instance {
"/": { "type": "object", "name": "SomeTitle" },
"/prop1": { "type": ["string", "number"] }
} The instance is validated against both the outer schema and the However, I realized that that whole line of thought doesn't make sense in this case because annotations provide information about an instance and for code gen, we don't have an instance. So, still have no idea what we should do about |
class SomeTitle {
prop1: string | number;
} This implies that the language supports unions. Many languages don't, like C#. I feel we need to stay within the intersection of language support as much as possible. |
Is there any reason why we need to support |
Not necessarily. A language that doesn't support unions would just need to introduce a type that represents a union. For example, a type like
One of our foundational principles is that people should be able to use the same schemas for code gen as they use for validation. Therefore, we don't want to disallow any keywords. However, ignoring |
The not keyword actually has two purposes from the perspective of a data definition, which makes this issue kinda complex, however, let's start simple.
Restricting types
The
not
keywords primary role is to define subschemas which the instance data should not validate against. This means that if you have defined a schema such as the following:The only object that will validate is
{"prop1": 2}
and not{"prop1": "string value"}
. This means I would expect the following class:and not the loose type (even though it could be an option):
Question is, should we infer such a strict type, or simply accept the broader type and ignore
not
?Including types
If you nest
not
keywords, you can actually define new types. Given the following schema:The following data is validated
{"prop2": "string value"}
and{"prop2": 2}
is rejected. This means I would expect that the following class:Would we care about such a case?
The text was updated successfully, but these errors were encountered: