Vscode-yaml: [BUG] If blocks don't evaluate properties correctly

Created on 19 Nov 2020  路  4Comments  路  Source: redhat-developer/vscode-yaml

Describe the bug

Unless I'm being super stupid - conditional matching does not work in "if" blocks - all conditions seem to be ignored and the else block always executes.

Expected Behavior

If an "if"'s condition evaluates to true, it should match the then schema

Current Behavior

The else schema is always evaluated.

Steps to Reproduce

  1. Associate this JSON schema with a YAML file:
{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "http://example.com/example.json",
    "type": "object",
    "title": "The root schema",
    "description": "The root schema comprises the entire JSON document.",
    "default": [],
    "properties": {
        "name": {
            "type": "string",
        },
        "var": {
            "type": "string",
        }
    },
    "if": {
        "properties": {
            "var": {
                "type": "string"
            }
        }
    },
    "then": {
        "required": [
            "pineapple"
        ]
    },
    "else": {
        "required": [
            "tomato"
        ]
    },
    "additionalProperties": true
}
  1. This YAML file:
name: aName
var: something
inputs:
  1. See that the schema is informing that "tomato" is required, when "pineapple" should be required instead, as var is quite clearly a string type.

Although this is using JSON - the data is a YAML to JSON conversion - the schema holds true and requires pineapple here https://jsonschema.dev/s/PaRXa

Environment

  • [ ] Windows
  • [x] Mac
  • [ ] Linux
  • [ ] other (please specify)
bug

Most helpful comment

I start release process, I hope to finish in a few hours.

All 4 comments

I just narrowed down odd behavior to the same issue. In my case I use a pattern that begins with

   "allOf": [
        {
            "$ref": "#/definitions/type"
        },
        {
            "if": {
                "properties": {
                    "type": {
                        "const": "metadata-registry"
                    }
                }
            },
            "then": {
                "$ref": "#/definitions/metadata"
            }
        },

to select definitions based on a type key in the YAML file. None of them are being selected. This did work on previous versions of the extension (before 0.12.0)

Many thanks for such a fast turnaround! How/when will the update from the language server be picked up by this extension?

I start release process, I hope to finish in a few hours.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tracker1 picture tracker1  路  5Comments

teresaejunior picture teresaejunior  路  4Comments

hppsc1215 picture hppsc1215  路  7Comments

Deilan picture Deilan  路  6Comments

gauthamp10 picture gauthamp10  路  5Comments