When adding a yaml-schema that resides in the same workspace as the yaml-files it applies to, it is erroneously validated against itself
See original GitHub issueDescribe the bug
Version 0.17.0.
When you use a YAML-file as a schema in the same workspace as the files you validate reside, the language-server tries to validate the schema against itself. As shown below, globbing does not play into it.
(I have looked at https://github.com/redhat-developer/yaml-language-server/pull/427 which on the surface appeared to be related, but after setting up a test where globbing is not involved, I don’t think so.)
Expected Behavior
A YAML schema should not validate against itself, unless specified by the glob pattern.
Current Behavior
A YAML schema validates against itself, even if yaml.schemas
association does not specify it.
Steps to Reproduce
- Create new project in VSCode
- Add file
schema.yaml
containing
type: object
properties:
foo:
type: string
description: A foo property
additionalProperties: false
required: [ 'foo' ]
- Add file
instance.yaml
containing
foo: bar
- Add
vscode/settings.json
containing
{
"yaml.schemas": {
"http://json-schema.org/draft-07/schema#": ["/schema.yaml"],
"./schema.yaml": [ "/instance.yaml" ]
}
}
Observe:
It is being validated against itself. If you add yet another file instance2.yaml
containing
qux: quux
It is, correctly, not being validated against /schema.yaml
.
Edit: instance.yaml
on the other hand, is, correctly, being validated against `/schema.yaml’
Environment
- Windows
- Mac
- Linux
- other (please specify)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:6 (1 by maintainers)
Top GitHub Comments
This is a very annoying bug. Would be so good if this was fixed.
The workaround suggested by @gorkem does not work for me, see screenshot
I cannot unselect validation against itself.
This seems to be related to how the mappings are processed from settings. A workaround until a fix is available Is to remove the json-schema mapping from
settings.json
and use inlined mapping by adding# yaml-language-server: $schema=https://json-schema.org/draft-07/schema
as the first line of the schema file.