redhat-developer / redhat-developer/vscode-yaml

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
#477 6 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

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

  • Windows
  • Mac
  • Linux
  • other (please specify)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with vscode/settings.json, schema.yaml, and instance.yaml using the documented yaml.schemas associations. Start by tracing the language server's schema selection and validation flow for a schema in the same workspace. Done means schema.yaml is not validated against itself unless its association explicitly matches it, while instance.yaml remains validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode, yaml
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.