this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

encoding/jsonschema: recognize matchN in Generate

Currently `matchN` is used by `Extract` to represent
`anyOf`, `allOf` and `not`, but not recognized by `Generate`.

This CL changes `Generate` to recognize `matchN`.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I13bad834850648338e4e92627293ef77ba6a6f0c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1224271
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

+314 -201
+1
encoding/jsonschema/external_test.go
··· 252 252 // invokes Generate on it, then returns the result of invoking Extract on 253 253 // the result of that. 254 254 func roundTripViaGenerate(t *testing.T, schemaValue cue.Value) (cue.Value, error) { 255 + t.Logf("round tripping from schema %#v", schemaValue) 255 256 ctx := schemaValue.Context() 256 257 // Generate JSON Schema from the extracted CUE. 257 258 // Note: 2020_12 is the only version that we currently support.
+2 -2
encoding/jsonschema/external_teststats.txt
··· 9 9 10 10 v3-roundtrip: 11 11 schema extract (pass / total): 225 / 1363 = 16.5% 12 - tests (pass / total): 699 / 4803 = 14.6% 13 - tests on extracted schemas (pass / total): 699 / 872 = 80.2% 12 + tests (pass / total): 746 / 4803 = 15.5% 13 + tests on extracted schemas (pass / total): 746 / 872 = 85.6% 14 14 15 15 Optional tests: 16 16
+88
encoding/jsonschema/generate.go
··· 338 338 return g.makeCallItem(v, args) 339 339 } 340 340 if isConcreteScalar(v) { 341 + if err := v.Err(); err != nil { 342 + g.addError(v, fmt.Errorf("error found in schema: %v", err)) 343 + return &itemFalse{} 344 + } 341 345 syntax := v.Syntax() 342 346 expr, ok := syntax.(ast.Expr) 343 347 if !ok { ··· 496 500 &itemType{kinds: []string{"array"}}, 497 501 &itemItemsBounds{constraint: constraint, n: int(n)}, 498 502 }, 503 + } 504 + 505 + case "matchN": 506 + // matchN is generated by Extract for oneOf, anyOf, allOf, and not. 507 + // - matchN(1, [a, b, c, ...]) represents oneOf 508 + // - matchN(0, [x]) represents not 509 + // - matchN(>=1, [a, b, c, ...]) represents anyOf 510 + // - matchN(N, [a, b, c, ...]) where N == len(list) represents allOf 511 + if len(args) != 3 { 512 + // Unrecognized form, accept anything 513 + return &itemTrue{} 514 + } 515 + 516 + // Extract the constraint from the first argument. 517 + // It can be a literal int (0, 1, N) or a unary expression (>=1). 518 + constraintVal := args[1] 519 + op, opArgs := constraintVal.Expr() 520 + 521 + // Extract the list of items from the second argument. 522 + listVal := args[2] 523 + listIter, err := listVal.List() 524 + if err != nil { 525 + // Not a list, accept anything 526 + return &itemTrue{} 527 + } 528 + 529 + // Collect all items in the list 530 + var items []item 531 + for listIter.Next() { 532 + items = append(items, g.makeItem(listIter.Value())) 533 + } 534 + 535 + if len(items) == 0 { 536 + // Empty list, accept anything 537 + return &itemTrue{} 538 + } 539 + 540 + // Determine which combinator to use based on the constraint 541 + switch op { 542 + case cue.NoOp: 543 + // It's a simple integer literal 544 + n, err := constraintVal.Int64() 545 + if err != nil { 546 + // Not an integer, accept anything 547 + return &itemTrue{} 548 + } 549 + switch n { 550 + case 0: 551 + // matchN(0, [x]) represents not 552 + if len(items) != 1 { 553 + // Unexpected form, accept anything 554 + return &itemTrue{} 555 + } 556 + return &itemNot{elem: items[0]} 557 + case 1: 558 + // matchN(1, [a, b, c, ...]) represents oneOf 559 + return &itemOneOf{elems: items} 560 + default: 561 + // matchN(N, [...]) where N == len(list) represents allOf 562 + if int(n) == len(items) { 563 + return &itemAllOf{elems: items} 564 + } 565 + // Unknown matchN pattern, accept anything 566 + return &itemTrue{} 567 + } 568 + 569 + case cue.GreaterThanEqualOp: 570 + // matchN(>=1, [a, b, c, ...]) represents anyOf 571 + if len(opArgs) != 1 { 572 + return &itemTrue{} 573 + } 574 + n, err := opArgs[0].Int64() 575 + if err != nil { 576 + return &itemTrue{} 577 + } 578 + if n == 1 { 579 + return &itemAnyOf{elems: items} 580 + } 581 + // Unknown matchN pattern, accept anything 582 + return &itemTrue{} 583 + 584 + default: 585 + // Unknown operator, accept anything 586 + return &itemTrue{} 499 587 } 500 588 501 589 default:
+1 -1
encoding/jsonschema/generate_test.go
··· 55 55 // Round-trip test: convert generated JSON Schema back to CUE to validate 56 56 // First compile the AST to a CUE value, then marshal to JSON 57 57 schemaValue := ctx.BuildExpr(r) 58 - qt.Assert(t, qt.IsNil(schemaValue.Err())) 58 + qt.Assert(t, qt.IsNil(schemaValue.Err()), qt.Commentf("schema data: %q", data)) 59 59 60 60 schemaBytes, err := schemaValue.MarshalJSON() 61 61 qt.Assert(t, qt.IsNil(err))
+7 -28
encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json
··· 40 40 "data": { 41 41 "foo": "baz" 42 42 }, 43 - "valid": false, 44 - "skip": { 45 - "v3-roundtrip": "unexpected success" 46 - } 43 + "valid": false 47 44 }, 48 45 { 49 46 "description": "mismatch first", 50 47 "data": { 51 48 "bar": 2 52 49 }, 53 - "valid": false, 54 - "skip": { 55 - "v3-roundtrip": "unexpected success" 56 - } 50 + "valid": false 57 51 }, 58 52 { 59 53 "description": "wrong type", ··· 61 55 "foo": "baz", 62 56 "bar": "quux" 63 57 }, 64 - "valid": false, 65 - "skip": { 66 - "v3-roundtrip": "unexpected success" 67 - } 58 + "valid": false 68 59 } 69 60 ] 70 61 }, ··· 127 118 "bar": 2, 128 119 "baz": null 129 120 }, 130 - "valid": false, 131 - "skip": { 132 - "v3-roundtrip": "unexpected success" 133 - } 121 + "valid": false 134 122 }, 135 123 { 136 124 "description": "mismatch second allOf", ··· 138 126 "foo": "quux", 139 127 "bar": 2 140 128 }, 141 - "valid": false, 142 - "skip": { 143 - "v3-roundtrip": "unexpected success" 144 - } 129 + "valid": false 145 130 }, 146 131 { 147 132 "description": "mismatch both", 148 133 "data": { 149 134 "bar": 2 150 135 }, 151 - "valid": false, 152 - "skip": { 153 - "v3-roundtrip": "unexpected success" 154 - } 136 + "valid": false 155 137 } 156 138 ] 157 139 }, ··· 177 159 { 178 160 "description": "mismatch one", 179 161 "data": 35, 180 - "valid": false, 181 - "skip": { 182 - "v3-roundtrip": "unexpected success" 183 - } 162 + "valid": false 184 163 } 185 164 ] 186 165 },
+4 -16
encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json
··· 31 31 { 32 32 "description": "neither anyOf valid", 33 33 "data": 1.5, 34 - "valid": false, 35 - "skip": { 36 - "v3-roundtrip": "unexpected success" 37 - } 34 + "valid": false 38 35 } 39 36 ] 40 37 }, ··· 56 53 { 57 54 "description": "mismatch base schema", 58 55 "data": 3, 59 - "valid": false, 60 - "skip": { 61 - "v3-roundtrip": "unexpected success" 62 - } 56 + "valid": false 63 57 }, 64 58 { 65 59 "description": "one anyOf valid", ··· 69 63 { 70 64 "description": "both anyOf invalid", 71 65 "data": "foo", 72 - "valid": false, 73 - "skip": { 74 - "v3-roundtrip": "unexpected success" 75 - } 66 + "valid": false 76 67 } 77 68 ] 78 69 }, ··· 186 177 "foo": 2, 187 178 "bar": "quux" 188 179 }, 189 - "valid": false, 190 - "skip": { 191 - "v3-roundtrip": "unexpected success" 192 - } 180 + "valid": false 193 181 } 194 182 ] 195 183 },
+1 -4
encoding/jsonschema/testdata/external/tests/draft2020-12/infinite-loop-detection.json
··· 36 36 "data": { 37 37 "foo": "a string" 38 38 }, 39 - "valid": false, 40 - "skip": { 41 - "v3-roundtrip": "unexpected success" 42 - } 39 + "valid": false 43 40 } 44 41 ] 45 42 }
+3 -3
encoding/jsonschema/testdata/external/tests/draft2020-12/items.json
··· 72 72 "items": false 73 73 }, 74 74 "skip": { 75 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 75 + "v3-roundtrip": "generate error: error found in schema: [_]: explicit error (_|_ literal) in source" 76 76 }, 77 77 "tests": [ 78 78 { ··· 465 465 "items": false 466 466 }, 467 467 "skip": { 468 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 468 + "v3-roundtrip": "generate error: error found in schema: [_]: explicit error (_|_ literal) in source" 469 469 }, 470 470 "tests": [ 471 471 { ··· 611 611 "items": false 612 612 }, 613 613 "skip": { 614 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 614 + "v3-roundtrip": "generate error: error found in schema: [_]: explicit error (_|_ literal) in source" 615 615 }, 616 616 "tests": [ 617 617 {
+23 -92
encoding/jsonschema/testdata/external/tests/draft2020-12/not.json
··· 16 16 { 17 17 "description": "disallowed", 18 18 "data": 1, 19 - "valid": false, 20 - "skip": { 21 - "v3-roundtrip": "unexpected success" 22 - } 19 + "valid": false 23 20 } 24 21 ] 25 22 }, ··· 43 40 { 44 41 "description": "mismatch", 45 42 "data": 1, 46 - "valid": false, 47 - "skip": { 48 - "v3-roundtrip": "unexpected success" 49 - } 43 + "valid": false 50 44 }, 51 45 { 52 46 "description": "other mismatch", 53 47 "data": true, 54 - "valid": false, 55 - "skip": { 56 - "v3-roundtrip": "unexpected success" 57 - } 48 + "valid": false 58 49 } 59 50 ] 60 51 }, ··· 89 80 "data": { 90 81 "foo": "bar" 91 82 }, 92 - "valid": false, 93 - "skip": { 94 - "v3-roundtrip": "unexpected success" 95 - } 83 + "valid": false 96 84 } 97 85 ] 98 86 }, ··· 113 101 "foo": 1, 114 102 "bar": 2 115 103 }, 116 - "valid": false, 117 - "skip": { 118 - "v3-roundtrip": "unexpected success" 119 - } 104 + "valid": false 120 105 }, 121 106 { 122 107 "description": "property absent", ··· 138 123 { 139 124 "description": "number is invalid", 140 125 "data": 1, 141 - "valid": false, 142 - "skip": { 143 - "v3-roundtrip": "unexpected success" 144 - } 126 + "valid": false 145 127 }, 146 128 { 147 129 "description": "string is invalid", 148 130 "data": "foo", 149 - "valid": false, 150 - "skip": { 151 - "v3-roundtrip": "unexpected success" 152 - } 131 + "valid": false 153 132 }, 154 133 { 155 134 "description": "boolean true is invalid", 156 135 "data": true, 157 - "valid": false, 158 - "skip": { 159 - "v3-roundtrip": "unexpected success" 160 - } 136 + "valid": false 161 137 }, 162 138 { 163 139 "description": "boolean false is invalid", 164 140 "data": false, 165 - "valid": false, 166 - "skip": { 167 - "v3-roundtrip": "unexpected success" 168 - } 141 + "valid": false 169 142 }, 170 143 { 171 144 "description": "null is invalid", 172 145 "data": null, 173 - "valid": false, 174 - "skip": { 175 - "v3-roundtrip": "unexpected success" 176 - } 146 + "valid": false 177 147 }, 178 148 { 179 149 "description": "object is invalid", 180 150 "data": { 181 151 "foo": "bar" 182 152 }, 183 - "valid": false, 184 - "skip": { 185 - "v3-roundtrip": "unexpected success" 186 - } 153 + "valid": false 187 154 }, 188 155 { 189 156 "description": "empty object is invalid", 190 157 "data": {}, 191 - "valid": false, 192 - "skip": { 193 - "v3-roundtrip": "unexpected success" 194 - } 158 + "valid": false 195 159 }, 196 160 { 197 161 "description": "array is invalid", 198 162 "data": [ 199 163 "foo" 200 164 ], 201 - "valid": false, 202 - "skip": { 203 - "v3-roundtrip": "unexpected success" 204 - } 165 + "valid": false 205 166 }, 206 167 { 207 168 "description": "empty array is invalid", 208 169 "data": [], 209 - "valid": false, 210 - "skip": { 211 - "v3-roundtrip": "unexpected success" 212 - } 170 + "valid": false 213 171 } 214 172 ] 215 173 }, ··· 223 181 { 224 182 "description": "number is invalid", 225 183 "data": 1, 226 - "valid": false, 227 - "skip": { 228 - "v3-roundtrip": "unexpected success" 229 - } 184 + "valid": false 230 185 }, 231 186 { 232 187 "description": "string is invalid", 233 188 "data": "foo", 234 - "valid": false, 235 - "skip": { 236 - "v3-roundtrip": "unexpected success" 237 - } 189 + "valid": false 238 190 }, 239 191 { 240 192 "description": "boolean true is invalid", 241 193 "data": true, 242 - "valid": false, 243 - "skip": { 244 - "v3-roundtrip": "unexpected success" 245 - } 194 + "valid": false 246 195 }, 247 196 { 248 197 "description": "boolean false is invalid", 249 198 "data": false, 250 - "valid": false, 251 - "skip": { 252 - "v3-roundtrip": "unexpected success" 253 - } 199 + "valid": false 254 200 }, 255 201 { 256 202 "description": "null is invalid", 257 203 "data": null, 258 - "valid": false, 259 - "skip": { 260 - "v3-roundtrip": "unexpected success" 261 - } 204 + "valid": false 262 205 }, 263 206 { 264 207 "description": "object is invalid", 265 208 "data": { 266 209 "foo": "bar" 267 210 }, 268 - "valid": false, 269 - "skip": { 270 - "v3-roundtrip": "unexpected success" 271 - } 211 + "valid": false 272 212 }, 273 213 { 274 214 "description": "empty object is invalid", 275 215 "data": {}, 276 - "valid": false, 277 - "skip": { 278 - "v3-roundtrip": "unexpected success" 279 - } 216 + "valid": false 280 217 }, 281 218 { 282 219 "description": "array is invalid", 283 220 "data": [ 284 221 "foo" 285 222 ], 286 - "valid": false, 287 - "skip": { 288 - "v3-roundtrip": "unexpected success" 289 - } 223 + "valid": false 290 224 }, 291 225 { 292 226 "description": "empty array is invalid", 293 227 "data": [], 294 - "valid": false, 295 - "skip": { 296 - "v3-roundtrip": "unexpected success" 297 - } 228 + "valid": false 298 229 } 299 230 ] 300 231 },
+12 -48
encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json
··· 26 26 { 27 27 "description": "both oneOf valid", 28 28 "data": 3, 29 - "valid": false, 30 - "skip": { 31 - "v3-roundtrip": "unexpected success" 32 - } 29 + "valid": false 33 30 }, 34 31 { 35 32 "description": "neither oneOf valid", 36 33 "data": 1.5, 37 - "valid": false, 38 - "skip": { 39 - "v3-roundtrip": "unexpected success" 40 - } 34 + "valid": false 41 35 } 42 36 ] 43 37 }, ··· 59 53 { 60 54 "description": "mismatch base schema", 61 55 "data": 3, 62 - "valid": false, 63 - "skip": { 64 - "v3-roundtrip": "unexpected success" 65 - } 56 + "valid": false 66 57 }, 67 58 { 68 59 "description": "one oneOf valid", ··· 72 63 { 73 64 "description": "both oneOf valid", 74 65 "data": "foo", 75 - "valid": false, 76 - "skip": { 77 - "v3-roundtrip": "unexpected success" 78 - } 66 + "valid": false 79 67 } 80 68 ] 81 69 }, ··· 93 81 { 94 82 "description": "any value is invalid", 95 83 "data": "foo", 96 - "valid": false, 97 - "skip": { 98 - "v3-roundtrip": "unexpected success" 99 - } 84 + "valid": false 100 85 } 101 86 ] 102 87 }, ··· 208 193 "foo": "baz", 209 194 "bar": 2 210 195 }, 211 - "valid": false, 212 - "skip": { 213 - "v3-roundtrip": "unexpected success" 214 - } 196 + "valid": false 215 197 }, 216 198 { 217 199 "description": "neither oneOf valid (complex)", ··· 219 201 "foo": 2, 220 202 "bar": "quux" 221 203 }, 222 - "valid": false, 223 - "skip": { 224 - "v3-roundtrip": "unexpected success" 225 - } 204 + "valid": false 226 205 } 227 206 ] 228 207 }, ··· 246 225 { 247 226 "description": "both valid - invalid", 248 227 "data": 123, 249 - "valid": false, 250 - "skip": { 251 - "v3-roundtrip": "unexpected success" 252 - } 228 + "valid": false 253 229 } 254 230 ] 255 231 }, ··· 279 255 "data": { 280 256 "bar": 2 281 257 }, 282 - "valid": false, 283 - "skip": { 284 - "v3-roundtrip": "unexpected success" 285 - } 258 + "valid": false 286 259 }, 287 260 { 288 261 "description": "first valid - valid", ··· 307 280 "bar": 2, 308 281 "baz": 3 309 282 }, 310 - "valid": false, 311 - "skip": { 312 - "v3-roundtrip": "unexpected success" 313 - } 283 + "valid": false 314 284 } 315 285 ] 316 286 }, ··· 359 329 "foo": "foo", 360 330 "bar": 8 361 331 }, 362 - "valid": false, 363 - "skip": { 364 - "v3-roundtrip": "unexpected success" 365 - } 332 + "valid": false 366 333 }, 367 334 { 368 335 "description": "neither oneOf valid", 369 336 "data": { 370 337 "baz": "quux" 371 338 }, 372 - "valid": false, 373 - "skip": { 374 - "v3-roundtrip": "unexpected success" 375 - } 339 + "valid": false 376 340 } 377 341 ] 378 342 },
+1 -1
encoding/jsonschema/testdata/external/tests/draft2020-12/optional/id.json
··· 47 47 "data": "a string to match #/$defs/id_in_enum", 48 48 "valid": true, 49 49 "skip": { 50 - "v3-roundtrip": "conflicting values \"a string to match #/$defs/id_in_enum\" and {...} (mismatched types string and struct):\n instance.json:1:1\n" 50 + "v3-roundtrip": "conflicting values \"a string to match #/$defs/id_in_enum\" and {$id!:\"https://localhost:1234/draft2020-12/id/my_identifier.json\",type!:\"null\",...} (mismatched types string and struct):\n instance.json:1:1\nconflicting values \"a string to match #/$defs/id_in_enum\" and {...} (mismatched types string and struct):\n instance.json:1:1\ninvalid value \"a string to match #/$defs/id_in_enum\" (does not satisfy matchN): 0 matched, expected \u003e=1:\n instance.json:1:1\n" 51 51 } 52 52 }, 53 53 {
+1 -1
encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json
··· 48 48 "data": "a string", 49 49 "valid": true, 50 50 "skip": { 51 - "v3-roundtrip": "conflicting values \"a string\" and {...} (mismatched types string and struct):\n instance.json:1:1\n" 51 + "v3-roundtrip": "conflicting values \"a string\" and {...} (mismatched types string and struct):\n instance.json:1:1\ninvalid value \"a string\" (does not satisfy matchN): 0 matched, expected \u003e=1:\n instance.json:1:1\ncannot use \"a string\" (type _|_) as _ in argument 1 to matchN:\n instance.json:1:1\n" 52 52 } 53 53 }, 54 54 {
+1 -1
encoding/jsonschema/testdata/external/tests/draft2020-12/prefixItems.json
··· 79 79 ] 80 80 }, 81 81 "skip": { 82 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 82 + "v3-roundtrip": "generate error: error found in schema: explicit error (_|_ literal) in source" 83 83 }, 84 84 "tests": [ 85 85 {
+1 -1
encoding/jsonschema/testdata/external/tests/draft2020-12/properties.json
··· 168 168 } 169 169 }, 170 170 "skip": { 171 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 171 + "v3-roundtrip": "generate error: error found in schema: bar: explicit error (_|_ literal) in source" 172 172 }, 173 173 "tests": [ 174 174 {
+1 -1
encoding/jsonschema/testdata/external/tests/draft2020-12/propertyNames.json
··· 107 107 "propertyNames": false 108 108 }, 109 109 "skip": { 110 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 110 + "v3-roundtrip": "generate error: error found in schema: explicit error (_|_ literal) in source" 111 111 }, 112 112 "tests": [ 113 113 {
+2 -2
encoding/jsonschema/testdata/external/tests/draft2020-12/uniqueItems.json
··· 499 499 "items": false 500 500 }, 501 501 "skip": { 502 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 502 + "v3-roundtrip": "generate error: error found in schema: [_]: explicit error (_|_ literal) in source" 503 503 }, 504 504 "tests": [ 505 505 { ··· 848 848 "items": false 849 849 }, 850 850 "skip": { 851 - "v3-roundtrip": "cannot build value from JSON: explicit error (_|_ literal) in source" 851 + "v3-roundtrip": "generate error: error found in schema: [_]: explicit error (_|_ literal) in source" 852 852 }, 853 853 "tests": [ 854 854 {
+165
encoding/jsonschema/testdata/generate/matchn.txtar
··· 1 + -- test.cue -- 2 + package test 3 + 4 + // matchN patterns generated by Extract 5 + // These test the reverse transformation in Generate 6 + 7 + // matchN(1, [...]) -> oneOf 8 + oneOfTest?: matchN(1, [int, string, >5]) 9 + 10 + // matchN(0, [x]) -> not 11 + notTest?: matchN(0, [int]) 12 + 13 + // matchN(>=1, [...]) -> anyOf 14 + anyOfTest?: matchN(>=1, [int, string, bool]) 15 + 16 + // matchN(N, [...]) where N == len -> allOf 17 + allOfTest?: matchN(3, [int, >5, <100]) 18 + 19 + // Edge cases 20 + singleOneOf?: matchN(1, [string]) 21 + singleNot?: matchN(0, [bool]) 22 + singleAnyOf?: matchN(>=1, [int]) 23 + singleAllOf?: matchN(1, [int]) 24 + 25 + // Combined with other constraints 26 + complexOneOf?: matchN(1, [int & >0, string & =~"^[a-z]+$", bool]) & !=null 27 + complexAnyOf?: matchN(>=1, [int, string]) & !=5 28 + 29 + -- datatest/tests.cue -- 30 + package datatest 31 + 32 + ok1: data: { 33 + oneOfTest: 1 34 + notTest: "not an int" 35 + anyOfTest: true 36 + allOfTest: 10 37 + singleOneOf: "hello" 38 + singleNot: 123 39 + singleAnyOf: 42 40 + singleAllOf: 7 41 + complexOneOf: true 42 + complexAnyOf: "test" 43 + } 44 + 45 + ok2: data: {} 46 + 47 + oneOfMultipleMatch: { 48 + data: oneOfTest: 7 49 + error: true 50 + } 51 + 52 + notMatch: { 53 + data: notTest: 5 54 + error: true 55 + } 56 + 57 + allOfNotMatch: { 58 + data: allOfTest: 200 59 + error: true 60 + } 61 + 62 + -- out/generate-v3/schema -- 63 + { 64 + $schema: "https://json-schema.org/draft/2020-12/schema" 65 + type: "object" 66 + properties: { 67 + allOfTest: { 68 + allOf: [{ 69 + type: "number" 70 + }, { 71 + type: "integer" 72 + exclusiveMaximum: 100 73 + exclusiveMinimum: 5 74 + }] 75 + } 76 + anyOfTest: { 77 + anyOf: [{ 78 + type: "integer" 79 + }, { 80 + type: "string" 81 + }, { 82 + type: "boolean" 83 + }] 84 + } 85 + complexAnyOf: { 86 + anyOf: [{ 87 + type: "integer" 88 + }, { 89 + type: "string" 90 + }] 91 + not: { 92 + const: 5 93 + } 94 + } 95 + complexOneOf: { 96 + not: { 97 + const: null 98 + } 99 + oneOf: [{ 100 + allOf: [{ 101 + type: "number" 102 + }, { 103 + type: "integer" 104 + exclusiveMinimum: 0 105 + }] 106 + }, { 107 + type: "string" 108 + pattern: "^[a-z]+$" 109 + }, { 110 + type: "boolean" 111 + }] 112 + } 113 + notTest: { 114 + not: { 115 + type: "integer" 116 + } 117 + } 118 + oneOfTest: { 119 + oneOf: [{ 120 + type: "integer" 121 + }, { 122 + type: "string" 123 + }, { 124 + type: "number" 125 + exclusiveMinimum: 5 126 + }] 127 + } 128 + singleAllOf: { 129 + oneOf: [{ 130 + type: "integer" 131 + }] 132 + } 133 + singleAnyOf: { 134 + anyOf: [{ 135 + type: "integer" 136 + }] 137 + } 138 + singleNot: { 139 + not: { 140 + type: "boolean" 141 + } 142 + } 143 + singleOneOf: { 144 + oneOf: [{ 145 + type: "string" 146 + }] 147 + } 148 + } 149 + } 150 + -- out/generate-v3/ok1 -- 151 + -- out/generate-v3/ok2 -- 152 + -- out/generate-v3/oneOfMultipleMatch -- 153 + oneOfMultipleMatch.data.oneOfTest: conflicting values 7 and string (mismatched types int and string): 154 + ./datatest/tests.cue:19:19 155 + oneOfMultipleMatch.data.oneOfTest: invalid value 7 (does not satisfy matchN): 2 matched, expected 1: 156 + 1:582 157 + ./datatest/tests.cue:19:19 158 + -- out/generate-v3/notMatch -- 159 + notMatch.data.notTest: invalid value 5 (does not satisfy matchN): 1 matched, expected 0: 160 + 1:543 161 + ./datatest/tests.cue:24:17 162 + -- out/generate-v3/allOfNotMatch -- 163 + allOfNotMatch.data.allOfTest: invalid value 200 (out of bound <100): 164 + 1:147 165 + ./datatest/tests.cue:29:19