JSON 架构:是否有字段指定字段的元数据?
JSON Schema: Is there a field to specify meta data for a field?
如果我有 JSON 架构,例如:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object"
}
JSON 架构规范中是否定义了允许我添加选项的字段?我正在考虑使用 JSON 模式本身来生成 UI 表单,但我想添加一个选项来隐藏该字段。所以我正在考虑做类似的事情:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object",
"options" : {
"isVisible": false
}
}
这是有效的 JSON 架构还是我可以用于此目的的标准字段?
默认情况下,JSON 模式评估器将忽略他们不认识的关键字,因此您可以自由创建新关键字,例如 options
。
但是,有一个关键字用于您在此处描述的目的:readOnly
和 writeOnly
:https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.9.4 设置 "writeOnly": true
应指示(对支持此关键字的工具) 属性 永远不可见。
如果我有 JSON 架构,例如:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object"
}
JSON 架构规范中是否定义了允许我添加选项的字段?我正在考虑使用 JSON 模式本身来生成 UI 表单,但我想添加一个选项来隐藏该字段。所以我正在考虑做类似的事情:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object",
"options" : {
"isVisible": false
}
}
这是有效的 JSON 架构还是我可以用于此目的的标准字段?
默认情况下,JSON 模式评估器将忽略他们不认识的关键字,因此您可以自由创建新关键字,例如 options
。
但是,有一个关键字用于您在此处描述的目的:readOnly
和 writeOnly
:https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.9.4 设置 "writeOnly": true
应指示(对支持此关键字的工具) 属性 永远不可见。