github.com/kaptinlin/jsonschema@v0.4.6/testdata/JSON-Schema-Test-Suite/tests/draft2020-12/oneOf.json (about)

     1  [
     2      {
     3          "description": "oneOf",
     4          "schema": {
     5              "$schema": "https://json-schema.org/draft/2020-12/schema",
     6              "oneOf": [
     7                  {
     8                      "type": "integer"
     9                  },
    10                  {
    11                      "minimum": 2
    12                  }
    13              ]
    14          },
    15          "tests": [
    16              {
    17                  "description": "first oneOf valid",
    18                  "data": 1,
    19                  "valid": true
    20              },
    21              {
    22                  "description": "second oneOf valid",
    23                  "data": 2.5,
    24                  "valid": true
    25              },
    26              {
    27                  "description": "both oneOf valid",
    28                  "data": 3,
    29                  "valid": false
    30              },
    31              {
    32                  "description": "neither oneOf valid",
    33                  "data": 1.5,
    34                  "valid": false
    35              }
    36          ]
    37      },
    38      {
    39          "description": "oneOf with base schema",
    40          "schema": {
    41              "$schema": "https://json-schema.org/draft/2020-12/schema",
    42              "type": "string",
    43              "oneOf" : [
    44                  {
    45                      "minLength": 2
    46                  },
    47                  {
    48                      "maxLength": 4
    49                  }
    50              ]
    51          },
    52          "tests": [
    53              {
    54                  "description": "mismatch base schema",
    55                  "data": 3,
    56                  "valid": false
    57              },
    58              {
    59                  "description": "one oneOf valid",
    60                  "data": "foobar",
    61                  "valid": true
    62              },
    63              {
    64                  "description": "both oneOf valid",
    65                  "data": "foo",
    66                  "valid": false
    67              }
    68          ]
    69      },
    70      {
    71          "description": "oneOf with boolean schemas, all true",
    72          "schema": {
    73              "$schema": "https://json-schema.org/draft/2020-12/schema",
    74              "oneOf": [true, true, true]
    75          },
    76          "tests": [
    77              {
    78                  "description": "any value is invalid",
    79                  "data": "foo",
    80                  "valid": false
    81              }
    82          ]
    83      },
    84      {
    85          "description": "oneOf with boolean schemas, one true",
    86          "schema": {
    87              "$schema": "https://json-schema.org/draft/2020-12/schema",
    88              "oneOf": [true, false, false]
    89          },
    90          "tests": [
    91              {
    92                  "description": "any value is valid",
    93                  "data": "foo",
    94                  "valid": true
    95              }
    96          ]
    97      },
    98      {
    99          "description": "oneOf with boolean schemas, more than one true",
   100          "schema": {
   101              "$schema": "https://json-schema.org/draft/2020-12/schema",
   102              "oneOf": [true, true, false]
   103          },
   104          "tests": [
   105              {
   106                  "description": "any value is invalid",
   107                  "data": "foo",
   108                  "valid": false
   109              }
   110          ]
   111      },
   112      {
   113          "description": "oneOf with boolean schemas, all false",
   114          "schema": {
   115              "$schema": "https://json-schema.org/draft/2020-12/schema",
   116              "oneOf": [false, false, false]
   117          },
   118          "tests": [
   119              {
   120                  "description": "any value is invalid",
   121                  "data": "foo",
   122                  "valid": false
   123              }
   124          ]
   125      },
   126      {
   127          "description": "oneOf complex types",
   128          "schema": {
   129              "$schema": "https://json-schema.org/draft/2020-12/schema",
   130              "oneOf": [
   131                  {
   132                      "properties": {
   133                          "bar": {"type": "integer"}
   134                      },
   135                      "required": ["bar"]
   136                  },
   137                  {
   138                      "properties": {
   139                          "foo": {"type": "string"}
   140                      },
   141                      "required": ["foo"]
   142                  }
   143              ]
   144          },
   145          "tests": [
   146              {
   147                  "description": "first oneOf valid (complex)",
   148                  "data": {"bar": 2},
   149                  "valid": true
   150              },
   151              {
   152                  "description": "second oneOf valid (complex)",
   153                  "data": {"foo": "baz"},
   154                  "valid": true
   155              },
   156              {
   157                  "description": "both oneOf valid (complex)",
   158                  "data": {"foo": "baz", "bar": 2},
   159                  "valid": false
   160              },
   161              {
   162                  "description": "neither oneOf valid (complex)",
   163                  "data": {"foo": 2, "bar": "quux"},
   164                  "valid": false
   165              }
   166          ]
   167      },
   168      {
   169          "description": "oneOf with empty schema",
   170          "schema": {
   171              "$schema": "https://json-schema.org/draft/2020-12/schema",
   172              "oneOf": [
   173                  { "type": "number" },
   174                  {}
   175              ]
   176          },
   177          "tests": [
   178              {
   179                  "description": "one valid - valid",
   180                  "data": "foo",
   181                  "valid": true
   182              },
   183              {
   184                  "description": "both valid - invalid",
   185                  "data": 123,
   186                  "valid": false
   187              }
   188          ]
   189      },
   190      {
   191          "description": "oneOf with required",
   192          "schema": {
   193              "$schema": "https://json-schema.org/draft/2020-12/schema",
   194              "type": "object",
   195              "oneOf": [
   196                  { "required": ["foo", "bar"] },
   197                  { "required": ["foo", "baz"] }
   198              ]
   199          },
   200          "tests": [
   201              {
   202                  "description": "both invalid - invalid",
   203                  "data": {"bar": 2},
   204                  "valid": false
   205              },
   206              {
   207                  "description": "first valid - valid",
   208                  "data": {"foo": 1, "bar": 2},
   209                  "valid": true
   210              },
   211              {
   212                  "description": "second valid - valid",
   213                  "data": {"foo": 1, "baz": 3},
   214                  "valid": true
   215              },
   216              {
   217                  "description": "both valid - invalid",
   218                  "data": {"foo": 1, "bar": 2, "baz" : 3},
   219                  "valid": false
   220              }
   221          ]
   222      },
   223      {
   224          "description": "oneOf with missing optional property",
   225          "schema": {
   226              "$schema": "https://json-schema.org/draft/2020-12/schema",
   227              "oneOf": [
   228                  {
   229                      "properties": {
   230                          "bar": true,
   231                          "baz": true
   232                      },
   233                      "required": ["bar"]
   234                  },
   235                  {
   236                      "properties": {
   237                          "foo": true
   238                      },
   239                      "required": ["foo"]
   240                  }
   241              ]
   242          },
   243          "tests": [
   244              {
   245                  "description": "first oneOf valid",
   246                  "data": {"bar": 8},
   247                  "valid": true
   248              },
   249              {
   250                  "description": "second oneOf valid",
   251                  "data": {"foo": "foo"},
   252                  "valid": true
   253              },
   254              {
   255                  "description": "both oneOf valid",
   256                  "data": {"foo": "foo", "bar": 8},
   257                  "valid": false
   258              },
   259              {
   260                  "description": "neither oneOf valid",
   261                  "data": {"baz": "quux"},
   262                  "valid": false
   263              }
   264          ]
   265      },
   266      {
   267          "description": "nested oneOf, to check validation semantics",
   268          "schema": {
   269              "$schema": "https://json-schema.org/draft/2020-12/schema",
   270              "oneOf": [
   271                  {
   272                      "oneOf": [
   273                          {
   274                              "type": "null"
   275                          }
   276                      ]
   277                  }
   278              ]
   279          },
   280          "tests": [
   281              {
   282                  "description": "null is valid",
   283                  "data": null,
   284                  "valid": true
   285              },
   286              {
   287                  "description": "anything non-null is invalid",
   288                  "data": 123,
   289                  "valid": false
   290              }
   291          ]
   292      }
   293  ]