redhat-developer / vscode-yaml

YAML support for VS Code with built-in kubernetes syntax support
MIT License
652 stars 221 forks source link

JSON schema inline validation partially working in VSCode #1045

Closed jiyuchen-stripe closed 1 month ago

jiyuchen-stripe commented 1 month ago

Is your enhancement related to a problem? Please describe.

JSON schema inline validation partially working

Describe the solution you would like

We would like the validation to work :)

Describe alternatives you have considered

Additional context

Hi team!

It seems for some JSON schema, the inline documentation and validation is partially working in VSCode. I am not sure if this is a bug, or a feature not supported with the extension.

The JSON schema (named Test.json) I was using:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "anyOf": [
      {
          "$ref": "#/definitions/HelloWorld"
      },
      {
          "$ref": "#/definitions/HelloWorldV2"
      }
  ],
  "definitions": {
      "HelloWorld": {
          "description": "Some description",
          "properties": {
              "name": {
                "description": "The name of the HelloWorld resource.",
                "type": "string"
              },
              "status": {
                "description": "The status of the HelloWorld resource.",
                "type": "integer"
              }
          },
          "title": "HelloWorld",
          "type": "object"
      },
      "HelloWorldV2": {
            "description": "Some description",
            "properties": {
                "default": {
                    "$ref": "#/definitions/HelloWorld"
                }
            },
            "title": "HelloWorld V 2",
            "type": "object"
      }
  },
  "type": "object"
}

And in .vscode/settings.json I added a mapping from Test.json to test.yaml.

  "yaml.schemas": {
        "Test.json": "test.yaml"
   }

Then, only inline documentation works. If I made a type violation error (e.g. give a string value to status), no validation error is shown. I feel like if there is something wrong with the JSON schema, it shouldn't be partially working...

The problem seems to be related to HelloWorldV2 referencing the entire #/definitions/HelloWorld. If I delete that, it works.

Any ideas or insights? Thanks!