【发布时间】:2022-01-23 07:56:10
【问题描述】:
我已经看过了:
- Properties based on enum value in JSON Schema
- JSON schema for dynamic properties
- JSON Schema $ref for properties
我需要我的 JSON 模式来强制一个对象具有枚举中的所有属性,我不知道如何。
stuff.list.json
注意:想象一下,但要长得多。
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "ListOfStuff",
"description": "List of stuff",
"enum": [
"Thing1",
"Thing2",
"Thing3"
],
"uniqueItems": true
}
stuff.schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Stuff Defined",
"description": "Stuff in detail",
"type": "object",
"properties": {
/* a property for each enum value of stuff.list.json */: { <----- ???
"type": "array",
"items": { /* Schema for each item */ }
}
},
"required": [ /* $ref: ./stuff.list.json ?? */ ]
}
我希望它强制执行的输出是:
{
"Thing1": [],
"Thing2": [],
"Thing3": []
}
【问题讨论】:
标签: json jsonschema