-
Notifications
You must be signed in to change notification settings - Fork 32
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
Checking support for the key words “oneOf” and “allOf” #72
Comments
Let's look at this part of your schema. "allOf": [
{
"properties": {
"label": { "const": "GTIN" }
}
},
{
"type": "array",
"items": {
"type": "string",
"pattern": "^[0-9]{13}$"
},
"minItems": 1
}
] The If I remove the parts that aren't doing anything, we end up with the following, which shows another problem. "oneOf": [
{
"type": "array",
"items": {
"type": "string",
"pattern": "^[0-9]{13}$"
},
"minItems": 1
},
{
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"minItems": 1
}
] The Next, I've refactored the schema again. The behavior of the schema still hasn't changed, but I did change a couple keywords in order to simplify it. {
"type": "object",
"allOf": [
{
"type": "array",
"items": {
"type": "string",
"not": { "pattern": "^[0-9]{13}$" }
},
"minItems": 1
}
]
} Now we see the biggest problem with the schema. This is saying the value must be an object AND that it must be an array. Of course that's not possible, so this sub-schema will always fail no matter what value it's validating. So, if we refactor the schema one last time, we end up with the following. {
"type": "object",
"properties": {
"context": false
},
"required": ["context"]
} The "context" property is required by the Here's my best guess at the structure you were trying to describe. {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/calculation_preferences",
"type": "object",
"properties": {
"context": {
"type": "object",
"properties": {
"GTIN": {
"type": "array",
"items": {
"type": "string",
"pattern": "^[0-9]{13}$"
},
"minItems": 1
},
"selection group": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"minItems": 1
}
},
"oneOf": [
{ "required": ["GTIN"] },
{ "required": ["selection group"] }
]
}
},
"required": ["context"]
} |
This is fine.
I suggest to reconsider this view a bit more.
Do you find the shown test data example helpful and reasonable? I am trying to switch an object property according to its identifier or “label”.
Can the understanding evolve for more desirable data model design approaches?
It seems that you interpreted the JSON schema code in a direction which I did not intent.
I interpret your suggestion in the way that an object would get the properties “GTIN” and “selection group”. |
The message “ |
With the exception of the last schema, I'm not trying to interpret your intent. I'm trying to help you understand what your schema actually describes, not what you intended it to describe. Everything I told you about how the schema behaves as written is correct.
It was helpful, but it wasn't enough for me to understand what you're trying to do, especially because it looks quite different than what your schema describes. Your schema seems to describe a complex assertion, but you only have one example and don't say whether it should pass or fail. If you can provide more examples including whether they should pass or fail validation, I can be more confident about what you want the schema to describe.
"oneOf": [
{ "required": ["GTIN"] },
{ "required": ["selection group"] }
] That is the part of my suggested schema that asserts that one and only one of the properties "GTIN" and "selection group" can be used in the "context" object.
Based on my best guess about the structure you are trying to describe, I don't think that pattern (or |
The shown test data should get accepted (“pass”) by a corresponding JSON schema file. 💭 Can you agree to the expectation that some information should be applied to an item only after the affected item got a label assigned (for the discussed use case)?
I interpret this specification variant in the way that one property would become required while other properties can still be optional.
💭 Do you find any other specification approach more appropriate for guaranteeing that customised data structure settings are mapped to one configurable identifier?
🤔 Thus your view made me curious if involved developers (like @handrews) will get into the mood again to adjust remaining communication difficulties any further. |
That's not correct. The If you haven't already, try the schema I gave in a validator with some example data. If you find example data that doesn't validate the way you expect, then share that example here and we can work from there. |
This functionality can generally be helpful.
This is the outcome which would be desirable for my data model. But: 🤔
💭 I would prefer to achieve consensus on the aspect if the suggestion by Henry Andrews from 2022-07-21 (according to an intermediate design alternative for the functionality “propertyDependencies”) can produce the same validation result finally. |
@Markus-Elfring As best I can tell, @jdesrosiers is correct to state that I did not (and still do not) understand your question or use case. Therefore my suggestion probably is not what you were looking for and should not be considered authoritative. In any event, there's nothing that needs to be done or decided or resolved about that suggestion. It works as it is, and you can use it if you want. |
Both properties are allowed, but only one at a time. Seriously, try it out and see what happens. You can learn a lot about how it works with a little trial and error.
All properties in JSON Schema are optional unless explicitly required using the
Here are some examples of what Henry thought you were trying to do describe. The "label" property decides which of "GTIN" or "selection group" is allowed/required. {
"label": "GTIN",
"GTIN": [ "1234567890123" ]
} {
"label": "selection group",
"selection group": [ "foo" ]
} All of the solutions presented in that thread (there were three) were for describing a structure like what is shown in these examples. These examples are not how your data is structured and therefore, none of those solutions apply to this case. |
@handrews: I find such a feedback strange. 💭 I guess that you are very familiar with assigning different labels also to arrays (or objects) on demand.
💭 I got an other impression from the presented understanding difficulties.
💭 I hope so (because it looked so promising).
💭 I would like to extend its usage accordingly. Unfortunately, it seems that some involved developers can get confused. |
Such an effect can be desirable. 💭 It seems that an opposite understanding of data structure settings needs to be resolved.
💭 I suggest to reconsider this view once more if it should be determined how a data validation software should behave according to the official JSON schema specification.
I find this feedback interesting. 💭 How does it fit to a different understanding for the handling of optional (“not required”) items?
I would like to work only with required items in the discussed data model which excludes optional parts.
💭 It can be that the property “ |
It seems we've yet again reached the point where I can't understand you well enough to be of help to you. I'm trying, but it's been really hard to help you. I've shown you a schema that describes the structure you're trying to describe. You've refused to try the schema and see that it works and instead, you continue to guess incorrectly about what the schema does. I've shown in detail why the method you're original method doesn't work, yet you remain fixated on that approach. |
Your specification approach provides hints for further development considerations. 💭 Do you find the following data format description variant easier to understand? {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Calculation information",
"description": "settings for calculations",
"$id": "https://example.com/schemas/calculation_preferences",
"type": "object",
"required": ["context"],
"properties":
{
"context":
{
"type": "object",
"oneOf":
[
{
"required": ["GTIN"],
"GTIN":
{
"type": "array",
"minItems": 1,
"items":
{
"type": "string",
"pattern": "^[0-9]{13}$"
}
}
},
{
"required": ["selection group"],
"selection group":
{
"type": "array",
"minItems": 1,
"items":
{
"type": "string",
"minLength": 1
}
}
}
]
}
}
} |
You're close to something that will work. Your missing {
"properties": {
"GTIN": { ... }
},
"required": ["GTIN"],
"additionalProperties": false
} This will work the same as the other schema I gave you, but I don't recommend doing it this way. It's less efficient, more complicated, and will produce very confusing and unhelpful error messages. The original way I showed you is a much better solution. |
💭 Is such a view interesting also according to the aspect that a validation tool (which is based on the software “Vert.x JSON Schema 4.3.4”) accepted the mentioned data format description variant so far?
Would you like to explain this suggestion a bit more?
I got an other impression.
💭 I hope also that the involved software components can be improved considerably.
💭 It seems that we have not achieved consensus for the mentioned technical details so far. |
Questions
I took another look at the capabilities of the following software.
Version
4.3.4
Context
I constructed the following JSON schema file.
Test data example:
💭 Now I am wondering about the following error information.
🤔 I would appreciate further advices and solution ideas for these reported data type mismatches.
The text was updated successfully, but these errors were encountered: