redhat-developer / redhat-developer/vscode-yaml

Editing a YAML file with its schema in parallel will force apply the schema to itself as well

Open
#791 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

I'm writing a YAML data file and its schema (in YAML as well) in parallel. In multiple ways now, I tried to reference the schema to the data file so the data file gets validated, however when switching back to the schema file, it also get validated by itself, which of course results in many errors.

Interestingly, after adding the line # yaml-language-server: $schema=https://json-schema.org/draft/2020-12/schema to the schema file, VSC displayed that multiple schemas are available and I could select the "json schema" schema. But still the wrong validation will be applied and at at the status bar the yellow warning will still be displayed after selecting the schema.

My settings.json both globally and for the workspace do not contain any yaml.schemas or other keys for this plugin (except after selecting the correct schema after adding the meta schema line).

Expected Behavior

Only apply the schema file to the data file (where the reference is defined) and not to the schema file itself.

Current Behavior

The schema gets applied to itself.

Steps to Reproduce

  1. Create/copy both files inside a workspace
  2. Append # yaml-language-server: $schema=./SB_Flowchart_Schema.yaml to the data file
  3. Switch to the schema file and see the red errors.

Environment

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

Screenshots

Screenshots

image

After adding the additional yaml-language-server line to the schema file:
image

image

Data & Schema File

File contents
Schema File (called SB_Flowchart_Schema.yaml)
$schema: "https://json-schema.org/draft/2020-12/schema"

title: Schema with questions leading to results
description: |-
  This schema can be used to describe a set questions and results.
  For example an app can ask its user these questions in the defined order
  and return or use the result afterwards.

  This schema was originally created to define the SponsorBlock flowchart
  (see https://github.com/cole8888/SponsorBlock-Flowchart) in a structural way.

line_endings: unix

type: object

properties:

  results:
    type: object
    additionalProperties:
      type: object
      text:
        type: string
      category:
        type: string

required:
  - results
  - questions

additionalProperties: false
Data File (called SB_Flowchart.yaml)
# yaml-language-server: $schema=./SB_Flowchart_Schema.yaml

# texts might be markdown

results:  # sorted alphabetical by id TODO
  nothing:
    text: >-
      Do not submit anything!
  highlight:
    text: >-
      Highlight
    category: poi_highlight
  sponsor:
    text: >-
      Sponsor
    category: sponsor
  music_non_music:
    text: >-
      Music: Non-Music section
    category: music_offtopic
  platform_split_exclusive:
    text: >-
      While promoting their exclusive: _self promo_.
      While promoting the platform: _sponsor_.

questions:  # sorted alphabetical by id TODO
  is_skip_really_required:
    text: >-
      Is the video better off without skipping the segment or is the transition really bad?
    boolean: true
    answers:
      - text: "Yes"
        result: nothing
  skips_to_poi:
    text: >-
      Does the segment skip ahead to the point of interest?
    boolean: true
    answers:
      - text: "Yes"

  is_highlight:
    text: >-
      Does the segment meet any of the _highlight_ use cases?
  is_music_primary:
    text: >-
      Is music the primary aspect of the video?
  is_present_in_official:
    text: >-
      Is the segment present in the official music? (Spotify version?)
  is_part_of_song_playing:
    text: >-
      Is part of the song playing in the background of the segment?
  is_disclaimer_protecting:
    text: >-
      Is this a disclaimer intended to protect the viewer? (epilepsy, trigger warning, 18+)
  is_segment_near_end:
    text: >-
      Is the segment located at or near the end of the video?

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 SB_Flowchart.yaml and SB_Flowchart_Schema.yaml using the $schema directive described in the report, then inspect how the extension handles schema references when switching files. Done means the referenced schema validates only the data file and does not validate SB_Flowchart_Schema.yaml itself.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
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.