redhat-developer / redhat-developer/vscode-yaml

Validation Errors with Custom Tags, Anchors and Aliases in YAML Using Red Hat Extension

Open
#966 0 comments 1 reaction 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

When using the "YAML by Red Hat" extension in VS Code to validate a YAML file with custom tags and anchors against a provided JSON schema, I encounter validation errors. Specifically, I get errors on lines that use custom tags in conjunction with YAML anchors. The error message is "Nested mappings are not allowed in compact mappings."

The YAML, JSON schema, and relevant settings from settings.json in VS Code are provided below.

Expected Behavior

The YAML should be validated against the provided JSON schema without any errors, recognizing custom tags and anchors correctly.

Current Behavior

Validation errors occur on lines using custom tags in conjunction with YAML anchors.

Steps to Reproduce

  1. Set up VS Code with the "YAML by Red Hat" extension.
  2. Use the provided YAML and JSON schema.
  3. Set the provided settings in settings.json in VS Code.
  4. Open the YAML file in VS Code and observe the validation errors.

Environment

  • Windows (Replace with your environment)
  • Mac
  • Linux
  • other

YAML:

!config
  simulationDuration: 10
  scenario: !sim &scenario
    - "Simulation parsed from Yaml"
  director: !democc &director
    - "event triggered director"
    - *scenario
  workers:
    - !etsender &sender 
      - "event triggered sender"
      - *director
    - !etreceiver &receiver 
      - "event triggered receiver"
      - *director
  links:
    - - *sender 
      - *receiver

JSON Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "simulationDuration": {
      "type": "integer"
    },
    "scenario": {
      "type": "array",
      "$anchor": "scenario",
      "items": {
        "type": "string"
      }
    },
    "director": {
      "type": "array",
      "$anchor": "director",
      "items": {
        "type": "string"
      }
    },
    "workers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "etsender": {
            "type": "array",
            "$anchor": "sender",
            "items": {
              "type": "string"
            }
          },
          "etreceiver": {
            "type": "array",
            "$anchor": "receiver",
            "items": {
              "type": "string"
            }
          }
        },
        "required": ["etsender", "etreceiver"]
      }
    },
    "links": {
      "type": "array",
      "items": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    }
  },
  "required": ["simulationDuration", "scenario", "director", "workers", "links"]
}

settings.json in VS Code:

{
    "yaml.schemas": {
        "path/SimulationScenarioSchema.json": "Simple*.yaml"
    },
    "yaml.hover": true,
    "yaml.validate": true,
    "yaml.completion": true,
    "yaml.customTags": [
        "!config scalar",
        "!sim sequence",
        "!democc sequence",
        "!etsender sequence",
        "!etreceiver sequence"
    ]
}

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 validation errors in the VS Code YAML extension using the supplied YAML, JSON schema, and settings.json configuration. Start by testing the interaction between customTags, YAML anchors, aliases, and schema validation; done means the supplied YAML validates without the reported nested-mapping errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.