Microsoft/vscode

[json] JSON Schema anyOf error reporting is misleading

Open

#249,624 创建于 2025年5月23日

在 GitHub 查看
 (2 评论) (0 反应) (1 负责人)TypeScript (10,221 fork)batch import
feature-requesthelp wantedjson

仓库指标

Star
 (74,848 star)
PR 合并指标
 (平均合并 11小时 43分钟) (30 天内合并 1,000 个 PR)

描述

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version:
  • OS Version:

Steps to Reproduce:

  1. Save the following as repo_schema.json
{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "repo_schema.json",
  "type": "object",
  "properties": {
    "$schema": {
          "type": "string"
        },
    "merge_types": {
      "type": "object",
      "patternProperties": {
        "^.*$": {
          "properties": {
            "allow_squash": {
              "type": "boolean"
            },
            "allow_rebase_and_fast_forward": {
              "type": "boolean"
            },
            "allow_basic_no_fast_forward": {
              "type": "boolean"
            },
            "allow_rebase_with_merge": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "required": [
            "allow_squash",
            "allow_rebase_and_fast_forward",
            "allow_basic_no_fast_forward",
            "allow_rebase_with_merge"
          ],
          "anyOf": [
            {
              "properties": {
                "allow_squash": {
                  "const": true,
                  "description": "At least one merge type must be enabled."
                }
              }
            },
            {
              "properties": {
                "allow_rebase_and_fast_forward": {
                  "const": true,
                  "description": "At least one merge type must be enabled."
                }
              }
            },
            {
              "properties": {
                "allow_basic_no_fast_forward": {
                  "const": true,
                  "description": "At least one merge type must be enabled."
                }
              }
            },
            {
              "properties": {
                "allow_rebase_with_merge": {
                  "const": true,
                  "description": "At least one merge type must be enabled."
                }
              }
            }
          ]
        }
      },
      "additionalProperties": false
    }
  },
  "required": [],
  "additionalProperties": false
}
  1. Save the following as test.json
{
    "$schema": "repo_schema.json",
    "merge_types": {
        "main": {
            "allow_squash": false,
            "allow_rebase_and_fast_forward": false,
            "allow_basic_no_fast_forward": false,
            "allow_rebase_with_merge": false
        }
    }
}
  1. Ensure that the setting json.validate.enable=true
  2. You'll get a single yellow squiggly like this:

Image

This implies that the issue is with the first property, but in reality changing any of them to true makes the squiggly go away (which is correct).

The squiggly line should appear on all of the properties, since it's not just the first property that's failing to validate. Indeed other validators such as https://www.jsonschemavalidator.net/ do generate an error for each property:

Image

贡献者指南