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

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

Open priombiswas89 opened this issue 2 years ago • 0 comments

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

  • [X] Windows (Replace with your environment)
  • [x] 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"
    ]
}

priombiswas89 avatar Aug 18 '23 14:08 priombiswas89