【发布时间】:2017-07-05 15:55:57
【问题描述】:
我必须构建一个 Json 模式来格式化应用程序需要发送给另一个应用程序的每条消息。
我已经建立了这个:
{
'description': 'BLABLA',
'definitions': {
'M2M_message_input' : {
'type' : 'object',
'properties' : {
'command' : {
'type': 'string',
'enum' : ['read', 'write', 'list', 'reset priority']
},
'path' : {
'type' : 'string',
'pattern' : '^\/'
},
'value' : {'type' : 'string'},
'priority' : {
'type' : 'integer',
'maximum' : 255,
'exclusiveMaximum' : false,
'minimum' : 0,
'exclusiveMinimum' : false
}
},
'required': ['command'],
'dependencies' : {
'value' : ['priority']
},
"additionalProperties" : false
}
},
'type': 'object',
'$ref' : '#/definitions/M2M_message_input'
}
现在,我想根据命令值需要一些属性,例如:
- 如果命令设置为“读取”,我想要求路径,
- 如果命令设置为“写”,我想要求路径、值和优先级
等等……
我看到了一些关于这个的话题,比如JSON Schema - specify field is required based on value of another field,但我无法适应我的情况,通过使用草案 v4。
有什么建议吗?
【问题讨论】:
标签: json schema jsonschema