jsonschema - choosing between different objects in JSON-schema -
i'm creating schema receipts , want have master schema core concepts variety of different detail objects specialized receipt types (e.g. itemized hotel receipts, etc.) current implementation leveraging oneof
mechanism in json-schema
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "receipt", "type": "object", "properties": { ... "amount": { "type": "number" }, "detail": { "type": "object", "oneof": [ { "$ref": "general-detail.schema.json" }, { "$ref": "hotel-detail.schema.json" }, ... ] } } }
the problem approach when validate (using tv4), appears of schemas specified in oneof
being checked, , in fact, returning errors. can minimize effect getting rid of detail
property, moving oneof
schema-level (e.g. outside of properties
) , creating root property names in each of sub-schemas. however, in case, "missing required property: generaldetail" in event there's error when i'm validating hotel receipt type.
so 2 questions:
- is possible use generic
detail
property i'm doing , not have validator validate each sub-schema inoneof
structure (e.g. usingoneof
wrongly)? - if not possible, more fine having set of 'typed' detail properties (like 'generaldetail', 'hoteldetail', etc.) - there way specify group , 1 of them should exist in document being validated?
tia
all of schemas in oneof
need validated in order validator ensure 1 of schemas pass. if none pass or more 1 pass, validator needs tell validation results of each schema in order determine how fix error.
so, because validator telling why each of schemas failing doesn't mean expects of schemas pass.