redhat-developer / redhat-developer/vscode-yaml
Matches multiple schemas when only one must validate
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 829
- Forks
- 260
- Avg merge
- 5h 43m
- Merged PRs (30d)
- 1
Description
Question
I have complex json-schema file for validating configuration files for ansible. Below is short part with problem that I have. I'm not clear why "test 2" is not working (not properly matched against json-schema).
Based on this doc (https://json-schema.org/understanding-json-schema/reference/combining.html), oneOf=XOR, anyOf=OR, but my tests are not working.
I'm using vscode-yaml v0.23 (because v1.0.0 has an issue with autocompletion)
json-schema file:
{
"oneOf": [{ "$ref": "#/$defs/objectA" }, { "$ref": "#/$defs/objectB" }],
"$defs": {
"objectA": {
"type": "object",
"title": "Object A",
"properties": {
"objA": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "$ref": "#/$defs/name" },
"color": { "type": "string", "description": "color" }
},
"required": ["name"],
"additionalProperties": false
}
}
}
},
"objectB": {
"type": "object",
"title": "Object B",
"properties": {
"objB": {
"type": "object",
"properties": {
"name": { "$ref": "#/$defs/name" },
"size": { "type": "string", "description": "size" }
},
"required": ["name", "size"],
"additionalProperties": false
}
}
},
"name": {
"$comment": "this is common property for objA and objB",
"name": { "type": "string", "description": "name" }
}
}
}
First test
test 1
this file is not valid.
error: "Matches multiple schemas when only one must validate."
reason: (from my point of view) because match rule is set to "oneOf" and in this configuration is matched multiple rules.
objA:
- name: testA1
color: red
- name: testA2
objB:
size: middle
name: nameB
test 2
error: the same error as before
But it's not clear for me... match rule is 'oneOf', yaml config is changed that only one valid configuration is there (for object A) but validation ends with error. The question is, why is matched multiple schemas, when only one (object A) is configured (and matched from my point of view).
objA:
- name: testA1
color: red
- name: testA2
Another test
When I change oneOf to anyOf:
"anyOf": [{ "$ref": "#/$defs/objectA" }, { "$ref": "#/$defs/objectB" }]
This config file IS valid (it's wrong, becasue 'objB' is missing required parameter 'name'):
objA:
- name: testA1
color: red
- name: testA2
objB:
size: middle
Can anybody explain me where is the problem?
thx, martin
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the supplied schema and YAML examples using vscode-yaml v0.23, beginning with test 1 and test 2. Compare how oneOf, anyOf, and the referenced definitions are evaluated; done means determining whether the validator has a defect and documenting a precise, reproducible result or required project change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json, typescript, yaml
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100