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

[BUG] If blocks don't evaluate properties correctly #393

Closed
1 of 4 tasks
Chagrilled opened this issue Nov 19, 2020 · 4 comments
Closed
1 of 4 tasks

[BUG] If blocks don't evaluate properties correctly #393

Chagrilled opened this issue Nov 19, 2020 · 4 comments
Assignees
Labels

Comments

@Chagrilled
Copy link

Chagrilled commented Nov 19, 2020

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
  • Mac
  • Linux
  • other (please specify)
@chrisy
Copy link

chrisy commented Nov 19, 2020

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)

@evidolob
Copy link
Collaborator

Should be fixed with redhat-developer/yaml-language-server#357

@Chagrilled
Copy link
Author

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

@evidolob
Copy link
Collaborator

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

bleach31 pushed a commit to bleach31/vscode-yaml that referenced this issue Jan 25, 2022
bleach31 pushed a commit to bleach31/vscode-yaml that referenced this issue Jan 25, 2022
…snippet-without-array-symbol

fix codeCompletion with defaultSnippet and makdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants