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

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