jsonschema - JSON Schema: XOR on required fields -
json schemas have a required
property, lists required fields in json object. example, following (simplified) schema validates call sends text message user:
{ "type": "object", "properties": { "userid": { "type": "string" }, "text": { "type": "string" }, }, "required": ["userid", "text"] }
suppose want enable sending message multiple users, i.e. have either userid
field, or array of userids
(but not both or neither). there way express such condition in json schema?
naturally, there ways overcome problem in case - example, userid
array single element - general case interesting , useful.
not elegant @ all, think can hack out allof
, oneof
. like:
{ "allof" : [ { "type" : "object", "properties" : { // base properties come here } }, "oneof" : [ { "properties" : { "userids" : {"type" : "array"} }, "required" : ["userids"] }, { "properties" : { "userid" : {"type" : "number"} }, "required" : ["userid"] } ] ] }
Comments
Post a Comment