oneOf and schema with same attribute names

34 views
Skip to first unread message

marutha...@gmail.com

unread,
Jan 27, 2017, 6:24:28 AM1/27/17
to JSON Schema
Hi,

I have a below situation update vehicle which can update a car of update a jet properties, but only one at a time so I have mentioned "oneOf" refs (car and jet) but here both car and jet have tyre_sizes so "oneOf" is getting failed. How should I address the below situation of update_vehicle? Any references and pointers?

{
"id" : "update_vehicle",
"properties" : {
"type" : "object",
"oneOf" : [
{
"$ref" : "update_car"
},
{
"$ref" : "update_jet"
}
]
}
}


{
"id" : "update_car",
"properties" : {
"type" : "object",
"steering_size" : {
"type" : "string"
},
"tyre_size" : {
"type" : "string"
}
}
}

{
"id" : "update_car",
"properties" : {
"type" : "object",
"tyre_size" : {
"type" : "string"
}
}
}

Henry Andrews

unread,
Jan 27, 2017, 11:25:44 AM1/27/17
to JSON Schema, marutha...@gmail.com
Hello,
  Typically there is something in the schema for each branch of the "oneOf" that is unique to that branch.  For instance, a field "vehicleType" which is {"enum": ["car"]} in one branch and {"enum": ["jet"]} in the other.  That prevents any instance from matching both.

  Alternatively, if your types really overlap like this with no way to distinguish them, you might be fine with "anyOf".

thanks,
-henry
Reply all
Reply to author
Forward
0 new messages