Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local YAML schema applied to schema file itself #894

Closed
1 of 4 tasks
dmke opened this issue Mar 6, 2023 · 2 comments · Fixed by redhat-developer/yaml-language-server#898
Closed
1 of 4 tasks

Local YAML schema applied to schema file itself #894

dmke opened this issue Mar 6, 2023 · 2 comments · Fixed by redhat-developer/yaml-language-server#898
Labels

Comments

@dmke
Copy link

dmke commented Mar 6, 2023

Describe the bug

I've got the following files:

  • permission.schema.yml

    ---
    $id:      urn:x-intern
    $schema:  http://json-schema.org/draft/2020-12/schema
    
    type: object
    additionalProperties:
      type: object
      required: [name]
      additionalProperties: false
      properties:
        name:
          type: string
  • permission.yml

    ---
    foo:
      name: bar
  • .vscode/settings.json

    {
      "yaml.schemas": {
        "./permission.schema.yml": "permission.yml"
      }
    }

Expected Behavior

The permission.schema.yml should not be applied to itself:

  1. It has its own $schema property, pointing to the JSON schema draft 2020-12.
  2. The configured glob pattern (permission.yml) does not match permission.schema.yml.

Current Behavior

The local schema is applied to the local schema itself, resulting in a false problem detection:

image

Steps to Reproduce

  1. Open VSCode in an existing or new workspace/folder.
  2. Create the files permission.yml, permission.schema.yml and .vscode/settings.json.
  3. Open the permission.schema.yml in the editor.
  4. Observe the errors/problems.

Environment

  • Windows
  • Mac
  • Linux (Debian 11, X11, Gnome)
  • other (please specify)

Extension is redhat.vscode-yaml v1.11.0.

@odiak
Copy link

odiak commented Apr 21, 2023

I've got same problem,
and it doesn't happen if the schema file isn't referenced on yaml.schemas setting.

I roughly read source code of YAML language service, and maybe I found cause of the problem.

https://github.com/redhat-developer/yaml-language-server/blob/cf3f79202524ba979f1f4011636b85d08d81bdcb/src/languageservice/services/yamlSchemaService.ts#L408-L417

@bluefeet
Copy link

bluefeet commented Jun 19, 2023

This seems very much related to a problem I just found - that the $schema field is completely ignored. I would think that if $schema is declared in the YAML file it would override any settings or automatic schema.

Edit: Seems this can be done by adding a modeline. Weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants