vscode-yaml
vscode-yaml copied to clipboard
unevaluatedProperties with JSON Schema Draft 2019-09 and 2020-12 ignored
Describe the bug
Expected Behavior
YAML fileshould show error when undefined attribute for JSON Schema is configured when unevaluatedProperties is defined
Current Behavior
Undefined attributes are not showing an error
Steps to Reproduce
I am attempting to use allOf to reduce duplication in the schema for re-used attributes.
Below is an example Schema
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"$ref": "#/schema/policies",
"schema": {
"bmc": {
"allOf": [
{ "$ref": "#/schema/shared_attributes" },
{
"required": [ "lock_configuration" ],
"properties": {
"lock_configuration": {
"type": "boolean",
"default": false,
"title": "lock_configuration"
}
}
}
],
"description": "Control Remote Configuration.",
"title": "bmc",
"type": "object",
"unevaluatedProperties": false
},
"policies": {
"description": "Policies for the system.",
"type": "object",
"properties": {
"bmc": {
"type": "array",
"items": { "$ref": "#/schema/bmc" },
"title": "bmc"
}
}
},
"shared_attributes": {
"description": "Shared attributes for all policies.",
"required": [
"name"
],
"type": "object",
"properties": {
"description": {
"type": "string",
"default": "default",
"description": "Description of the policy.",
"pattern": "^$|^[a-zA-Z0-9]+[\\x00-\\xFF]*{0,1024}$",
"title": "description"
},
"name": {
"type": "string",
"default": "default",
"description": "Name of the Policy.",
"pattern": "^([a-zA-Z0-9][a-zA-Z0-9_\\.:-]{0,62})?[a-zA-Z0-9]$",
"title": "name"
}
},
"title": "shared_attributes"
}
}
}
Using this in conjunction with the YAML Extension from RedHat. Below is an example YAML File
---
bmc:
- name: test-schema
lock_configuration: false
foo: bar
Validation works for the valid attributes of name and lock_configuration but it also is not warning that foo is an invalid attribute. If the schema is changed to instead use the additionalProperties, then all attributes show as invalid. The only option I can find is to reduce allOf to a single dictionary, and use the additionalProperties inside that dictionary as shown below:
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"$ref": "#/schema/policies",
"schema": {
"bmc": {
"allOf": [
{
"additionalProperties": false,
"required": [ "lock_configuration", "name" ],
"properties": {
"name": { "$ref": "#/schema/shared_attributes/properties/name" },
"description": { "$ref": "#/schema/shared_attributes/properties/description" },
"lock_configuration": {
"type": "boolean",
"default": false,
"title": "lock_configuration"
}
}
}
],
"description": "Control Remote Configuration.",
"title": "bmc",
"type": "object",
"unevaluatedProperties": false
},
"policies": {
"description": "Policies for the system.",
"type": "object",
"properties": {
"bmc": {
"type": "array",
"items": { "$ref": "#/schema/bmc" },
"title": "bmc"
}
}
},
"shared_attributes": {
"description": "Shared attributes for all policies.",
"required": [
"name"
],
"type": "object",
"properties": {
"description": {
"type": "string",
"default": "default",
"description": "Description of the policy.",
"pattern": "^$|^[a-zA-Z0-9]+[\\x00-\\xFF]*{0,1024}$",
"title": "description"
},
"name": {
"type": "string",
"default": "default",
"description": "Name of the Policy.",
"pattern": "^([a-zA-Z0-9][a-zA-Z0-9_\\.:-]{0,62})?[a-zA-Z0-9]$",
"title": "name"
}
},
"title": "shared_attributes"
}
}
}
This schema then rejects the foo attribute, but is extremely sub-optimal.
May I ask that this to please be addressed?
Environment
- [x] Windows
- [ ] Mac
- [x] Linux
- [ ] other (please specify)