JSON schema - how to specify permutations of required properties -
below extract json schema.
i want specify both algorithm , results required.
additionally want specify:
- when
algorithmalgorithm1, results must 1 ofresults1,results2, orresults3. - when
algorithmalgorithm2, results must 1 ofresults2,results3, orresults4.
is possible?
"algorithm": { "description": "description...", "type": "string", "enum": [ "", "algorithm1", "algorithm2" ] }, "results": { "description": "description...", "type": "string", "enum": [ "", "results1", "results2", "results3", "results4" ] }, "required": ["algorithm", "results"]
thanks reference above @jruizaranguren, able figure out.
"required": ["results"], "results": { "type": "object", "oneof": [ { "$ref": "#/definitions/results1" }, { "$ref": "#/definitions/results2" } ] }, "definitions": { "results1": { "type": "object", "required": ["algorithm", "results"], "properties": { "algorithm": { "type": "string", "enum": [ "algorithm1" ] }, "results": { "type": "string", "allof": [ { "result": "results1" }, { "result": "results2" }, { "result": "results3" } ] } } }, "results2": { "type": "object", "required": ["algorithm", "results"], "properties": { "algorithm": { "type": "string", "enum": [ "algorithm2" ] }, "results": { "type": "string", "allof": [ { "result": "results2" }, { "result": "results3" }, { "result": "results4" } ] } } }
Comments
Post a Comment