vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

When adding a yaml-schema that resides in the same workspace as the yaml-files it applies to, it is erroneously validated against itself

Open karvus opened this issue 3 years ago • 6 comments

Describe 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

  1. Create new project in VSCode
  2. Add file schema.yaml containing
type: object
properties:
  foo: 
    type: string
    description: A foo property
additionalProperties: false
required: [ 'foo' ]
  1. Add file instance.yaml containing
foo: bar
  1. Add vscode/settings.json containing
{
    "yaml.schemas": { 
        "http://json-schema.org/draft-07/schema#": ["/schema.yaml"],
        "./schema.yaml": [ "/instance.yaml" ]
    } 
}

Observe:

image

It is being validated against itself. If you add yet another file instance2.yaml containing

qux: quux

image

It is, correctly, not being validated against /schema.yaml.

Edit: instance.yaml on the other hand, is, correctly, being validated against `/schema.yaml'

image

Environment

  • [x] Windows
  • [ ] Mac
  • [ ] Linux
  • [ ] other (please specify)

karvus avatar Apr 11 '21 15:04 karvus

I'm on a Mac, and seeing the same issue. A simple reproduction is this, which validates schema.yaml against itself:

{
  "yaml.schemas": {
    "schema.yaml": "asdf"
  }
}

odsock avatar Apr 15 '21 01:04 odsock

Hello, I can reproduce the same behavior on Linux.

Natsec avatar Aug 03 '21 12:08 Natsec

I also have this issue, is there a workaround or just deal with it for now?

dean-vanderwath-lab3 avatar Aug 23 '21 01:08 dean-vanderwath-lab3

Ran into this today. One possible workaround is to use JSON files for schemas.

Xiphoseer avatar Apr 19 '22 16:04 Xiphoseer

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.

gorkem avatar Apr 23 '22 17:04 gorkem

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.

image image

corneliusroemer avatar Aug 12 '22 15:08 corneliusroemer