【发布时间】:2016-03-09 05:09:27
【问题描述】:
我有一个示例 json:
{
"type": "persons",
"id": 2,
"attributes": {
"first": "something",
"second": "something else"
}
}
我必须为它创建一个架构(使用JSON API specs 和JSON schema docs):
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"type": {
"type": "string",
"pattern": "^persons$"
},
"id": {
"type": "integer"
},
"attributes": {
"type": "object",
"properties": {...}
}
},
"required": ["type", "id", "attributes"]
}
问题是:如果“type”唯一可接受的值是“persons”,我应该在模式模式中使用(如上)还是像枚举一样
"enum": ["persons"]
我无法从文档中得到任何明确的答案,尽管在规范中的示例中枚举用于单个值。那么你有什么看法呢?
【问题讨论】:
标签: json enums jsonschema json-api