首页 > 解决方案 > 使用 $schema 进行 VSC 验证并使用 additionalProperties = false

问题描述

我有一个 dataobject.json 和一个相应的 example.json。如果示例中的所有内容与数据对象中的符号相同,我喜欢比较两者。我在示例中添加了数据对象文件作为验证的模式。这有效,但仅适用于必填字段,不适用于可选属性。- 即使有一些问题,验证也没有发现问题。为了验证这些,我添加了 "additionalProperties": false 行。这通常有效,所以我找到了所有的偏差,但我也遇到了一个问题,即不允许使用属性 §schema。我该如何解决这个问题?

数据对象

{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"title": "GroupDO",
"required": [
    "id",
    "name"
],
"additionalProperties": false,
"properties": {
    "id": {
        "type": "string",
        "format": "uuid",
        "example": "5dd6c80a-3376-4bce-bc47-8t41b3565325",
        "description": "Unique id ."
    },
    "name": {
        "type": "string",
        "example": "ABD",
        "description": "The name."
    },
    "GroupSort": {
        "type": "integer",
        "format": "int32",
        "example": 1,
        "description": "Defines in which order the groups should appear."
    },
    "GroupTextList": {
        "type": "array",
        "description": "A descriptoin in multiple languages.",
        "items": {
            "$ref": "../../common/dataobjects/Description_1000_DO.json"
        }
    },
    "parentGroupId": {
        "type": "string",
        "format": "uuid",
        "example": "8e590f93-1ab6-40e4-a5f4-aa1eeb2b6a80",
        "description": "Unique id for the parent group."
    }
},
"description": "DO representing a group object. "}

这个例子

  { "$schema": "../dataobjects/GroupDO.json",
  "id": "18694b46-0833-4790-b780-c7897ap08500",
  "version": 1,
  "lastChange": "2020-05-12T13:57:39.935305",
  "sort": 3,
  "name": "STR",
  "parentGroupId": "b504273e-61fb-48d1-aef8-c289jk779709",
  "GroupTexts": [
    {
      "id": "7598b668-d9b7-4d27-a489-19e45h2bdad0",
      "version": 0,
      "lastChange": "2020-03-09T14:14:25.491787",
      "languageIsoCode": "de_DE",
      "description": "Tasche"
    },
    {
      "id": "376e82f8-837d-4bb2-a21f-a9e0ebd59e23",
      "version": 0,
      "lastChange": "2020-03-09T14:14:25.491787",
      "languageIsoCode": "en_GB",
      "description": "Bag"
    }
  ]
}

问题消息: 不允许使用属性 $schema

在此先感谢您的帮助。

标签: validationvisual-studio-codeproperties

解决方案


推荐阅读