JSON schema - how to specify permutations of required properties -


below extract json schema.

i want specify both algorithm , results required.

additionally want specify:

  • when algorithm algorithm1, results must 1 of results1, results2, or results3.
  • when algorithm algorithm2, results must 1 of results2, results3, or results4.

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

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -