validation - 使用 $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
在此先感谢您的帮助。
解决方案
推荐阅读
- spring - 带有 Spring Boot 的 Thymeleaf - 找不到静态资产 (CSS)
- python - XOR 运算符没有给出预期的结果?
- asp.net-mvc - Asp.Net MVC 电子邮件:在邮件标题中发现无效字符
- sql - 在 ASP.NET 页面上跟踪 SQL Server 作业的进度
- javascript - 未定义的变量反应教程
- c# - 在 C# 中操作 XSLT 文件
- r - dplyr:在不同列上选择 n 行列的有效方法
- javascript - 有条件地显示/隐藏 div
- javascript - 如何解构对象并排除属性?
- swift - a和b之和减去c是多少?