cuelang.org/go@v0.13.0/encoding/jsonschema/testdata/external/tests/draft2020-12/if-then-else.json (about)

     1  [
     2  	{
     3  		"description": "ignore if without then or else",
     4  		"schema": {
     5  			"$schema": "https://json-schema.org/draft/2020-12/schema",
     6  			"if": {
     7  				"const": 0
     8  			}
     9  		},
    10  		"tests": [
    11  			{
    12  				"description": "valid when valid against lone if",
    13  				"data": 0,
    14  				"valid": true
    15  			},
    16  			{
    17  				"description": "valid when invalid against lone if",
    18  				"data": "hello",
    19  				"valid": true
    20  			}
    21  		]
    22  	},
    23  	{
    24  		"description": "ignore then without if",
    25  		"schema": {
    26  			"$schema": "https://json-schema.org/draft/2020-12/schema",
    27  			"then": {
    28  				"const": 0
    29  			}
    30  		},
    31  		"tests": [
    32  			{
    33  				"description": "valid when valid against lone then",
    34  				"data": 0,
    35  				"valid": true
    36  			},
    37  			{
    38  				"description": "valid when invalid against lone then",
    39  				"data": "hello",
    40  				"valid": true
    41  			}
    42  		]
    43  	},
    44  	{
    45  		"description": "ignore else without if",
    46  		"schema": {
    47  			"$schema": "https://json-schema.org/draft/2020-12/schema",
    48  			"else": {
    49  				"const": 0
    50  			}
    51  		},
    52  		"tests": [
    53  			{
    54  				"description": "valid when valid against lone else",
    55  				"data": 0,
    56  				"valid": true
    57  			},
    58  			{
    59  				"description": "valid when invalid against lone else",
    60  				"data": "hello",
    61  				"valid": true
    62  			}
    63  		]
    64  	},
    65  	{
    66  		"description": "if and then without else",
    67  		"schema": {
    68  			"$schema": "https://json-schema.org/draft/2020-12/schema",
    69  			"if": {
    70  				"exclusiveMaximum": 0
    71  			},
    72  			"then": {
    73  				"minimum": -10
    74  			}
    75  		},
    76  		"tests": [
    77  			{
    78  				"description": "valid through then",
    79  				"data": -1,
    80  				"valid": true
    81  			},
    82  			{
    83  				"description": "invalid through then",
    84  				"data": -100,
    85  				"valid": false
    86  			},
    87  			{
    88  				"description": "valid when if test fails",
    89  				"data": 3,
    90  				"valid": true
    91  			}
    92  		]
    93  	},
    94  	{
    95  		"description": "if and else without then",
    96  		"schema": {
    97  			"$schema": "https://json-schema.org/draft/2020-12/schema",
    98  			"if": {
    99  				"exclusiveMaximum": 0
   100  			},
   101  			"else": {
   102  				"multipleOf": 2
   103  			}
   104  		},
   105  		"tests": [
   106  			{
   107  				"description": "valid when if test passes",
   108  				"data": -1,
   109  				"valid": true
   110  			},
   111  			{
   112  				"description": "valid through else",
   113  				"data": 4,
   114  				"valid": true
   115  			},
   116  			{
   117  				"description": "invalid through else",
   118  				"data": 3,
   119  				"valid": false
   120  			}
   121  		]
   122  	},
   123  	{
   124  		"description": "validate against correct branch, then vs else",
   125  		"schema": {
   126  			"$schema": "https://json-schema.org/draft/2020-12/schema",
   127  			"if": {
   128  				"exclusiveMaximum": 0
   129  			},
   130  			"then": {
   131  				"minimum": -10
   132  			},
   133  			"else": {
   134  				"multipleOf": 2
   135  			}
   136  		},
   137  		"tests": [
   138  			{
   139  				"description": "valid through then",
   140  				"data": -1,
   141  				"valid": true
   142  			},
   143  			{
   144  				"description": "invalid through then",
   145  				"data": -100,
   146  				"valid": false
   147  			},
   148  			{
   149  				"description": "valid through else",
   150  				"data": 4,
   151  				"valid": true
   152  			},
   153  			{
   154  				"description": "invalid through else",
   155  				"data": 3,
   156  				"valid": false
   157  			}
   158  		]
   159  	},
   160  	{
   161  		"description": "non-interference across combined schemas",
   162  		"schema": {
   163  			"$schema": "https://json-schema.org/draft/2020-12/schema",
   164  			"allOf": [
   165  				{
   166  					"if": {
   167  						"exclusiveMaximum": 0
   168  					}
   169  				},
   170  				{
   171  					"then": {
   172  						"minimum": -10
   173  					}
   174  				},
   175  				{
   176  					"else": {
   177  						"multipleOf": 2
   178  					}
   179  				}
   180  			]
   181  		},
   182  		"tests": [
   183  			{
   184  				"description": "valid, but would have been invalid through then",
   185  				"data": -100,
   186  				"valid": true
   187  			},
   188  			{
   189  				"description": "valid, but would have been invalid through else",
   190  				"data": 3,
   191  				"valid": true
   192  			}
   193  		]
   194  	},
   195  	{
   196  		"description": "if with boolean schema true",
   197  		"schema": {
   198  			"$schema": "https://json-schema.org/draft/2020-12/schema",
   199  			"if": true,
   200  			"then": {
   201  				"const": "then"
   202  			},
   203  			"else": {
   204  				"const": "else"
   205  			}
   206  		},
   207  		"tests": [
   208  			{
   209  				"description": "boolean schema true in if always chooses the then path (valid)",
   210  				"data": "then",
   211  				"valid": true
   212  			},
   213  			{
   214  				"description": "boolean schema true in if always chooses the then path (invalid)",
   215  				"data": "else",
   216  				"valid": false
   217  			}
   218  		]
   219  	},
   220  	{
   221  		"description": "if with boolean schema false",
   222  		"schema": {
   223  			"$schema": "https://json-schema.org/draft/2020-12/schema",
   224  			"if": false,
   225  			"then": {
   226  				"const": "then"
   227  			},
   228  			"else": {
   229  				"const": "else"
   230  			}
   231  		},
   232  		"skip": {
   233  			"v2": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n    generated.cue:3:9\n",
   234  			"v3": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n    generated.cue:3:9\n"
   235  		},
   236  		"tests": [
   237  			{
   238  				"description": "boolean schema false in if always chooses the else path (invalid)",
   239  				"data": "then",
   240  				"valid": false,
   241  				"skip": {
   242  					"v2": "could not compile schema",
   243  					"v3": "could not compile schema"
   244  				}
   245  			},
   246  			{
   247  				"description": "boolean schema false in if always chooses the else path (valid)",
   248  				"data": "else",
   249  				"valid": true,
   250  				"skip": {
   251  					"v2": "could not compile schema",
   252  					"v3": "could not compile schema"
   253  				}
   254  			}
   255  		]
   256  	},
   257  	{
   258  		"description": "if appears at the end when serialized (keyword processing sequence)",
   259  		"schema": {
   260  			"$schema": "https://json-schema.org/draft/2020-12/schema",
   261  			"then": {
   262  				"const": "yes"
   263  			},
   264  			"else": {
   265  				"const": "other"
   266  			},
   267  			"if": {
   268  				"maxLength": 4
   269  			}
   270  		},
   271  		"tests": [
   272  			{
   273  				"description": "yes redirects to then and passes",
   274  				"data": "yes",
   275  				"valid": true
   276  			},
   277  			{
   278  				"description": "other redirects to else and passes",
   279  				"data": "other",
   280  				"valid": true
   281  			},
   282  			{
   283  				"description": "no redirects to then and fails",
   284  				"data": "no",
   285  				"valid": false
   286  			},
   287  			{
   288  				"description": "invalid redirects to else and fails",
   289  				"data": "invalid",
   290  				"valid": false
   291  			}
   292  		]
   293  	}
   294  ]