cuelang.org/go@v0.13.0/encoding/openapi/testdata/oneof-resolve.txtar (about) 1 #ExpandReferences 2 #skip-v3 3 #skip-v3-noshare 4 -- in.cue -- 5 // OpenAPI title. 6 7 $version: "v1alpha1" 8 9 #T: { 10 shared: int 11 } 12 #T: {} | { 13 exact: string 14 } | { 15 regex: string 16 } 17 #T: {} | { 18 count: int 19 } | { 20 amount: int 21 } 22 #T: { 23 shared2: int 24 } 25 26 // This should be dedupped. 27 #T: {} | { 28 count: int 29 } | { 30 amount: int 31 } 32 33 #MyInt: int 34 35 #Foo: { 36 include: #T 37 exclude: [...#T] 38 count: #MyInt 39 } 40 41 #Incompatible: { 42 shared: int 43 } | { 44 shared: int 45 extra1: int 46 } | { 47 shared: int 48 extra2: int 49 } 50 51 #WithMap: { 52 shared: [string]: int 53 } | { 54 shared: [string]: int 55 extra: int 56 } | { 57 shared: string // incompatible 58 extra: int 59 } 60 61 #Embed: { 62 a?: int 63 64 close({}) | 65 close({b: #T}) | 66 close({c: int}) 67 68 #T: {b?: int} 69 70 close({}) | 71 close({d: #T}) | 72 close({e: int}) 73 74 // TODO: maybe support builtin to write this as 75 // oneof({}, 76 // {b: int}, 77 // {c: int}) 78 } 79 80 -- out/TestGenerateOpenAPI/out.json -- 81 { 82 "openapi": "3.0.0", 83 "info": { 84 "title": "OpenAPI title.", 85 "version": "v1alpha1" 86 }, 87 "paths": {}, 88 "components": { 89 "schemas": { 90 "Embed": { 91 "type": "object", 92 "properties": { 93 "a": { 94 "type": "integer" 95 }, 96 "d": { 97 "type": "object", 98 "properties": { 99 "b": { 100 "type": "integer" 101 } 102 } 103 }, 104 "e": { 105 "type": "integer" 106 }, 107 "b": { 108 "type": "object", 109 "properties": { 110 "b": { 111 "type": "integer" 112 } 113 } 114 }, 115 "c": { 116 "type": "integer" 117 } 118 }, 119 "allOf": [ 120 { 121 "oneOf": [ 122 { 123 "not": { 124 "anyOf": [ 125 { 126 "required": [ 127 "b" 128 ] 129 }, 130 { 131 "required": [ 132 "c" 133 ] 134 } 135 ] 136 } 137 }, 138 { 139 "required": [ 140 "b" 141 ] 142 }, 143 { 144 "required": [ 145 "c" 146 ] 147 } 148 ] 149 }, 150 { 151 "oneOf": [ 152 { 153 "not": { 154 "anyOf": [ 155 { 156 "required": [ 157 "d" 158 ] 159 }, 160 { 161 "required": [ 162 "e" 163 ] 164 } 165 ] 166 } 167 }, 168 { 169 "required": [ 170 "d" 171 ] 172 }, 173 { 174 "required": [ 175 "e" 176 ] 177 } 178 ] 179 } 180 ] 181 }, 182 "Embed.T": { 183 "type": "object", 184 "properties": { 185 "b": { 186 "type": "integer" 187 } 188 } 189 }, 190 "Foo": { 191 "type": "object", 192 "required": [ 193 "include", 194 "exclude", 195 "count" 196 ], 197 "properties": { 198 "include": { 199 "type": "object", 200 "properties": { 201 "shared": { 202 "type": "integer" 203 }, 204 "shared2": { 205 "type": "integer" 206 }, 207 "count": { 208 "type": "integer" 209 }, 210 "amount": { 211 "type": "integer" 212 }, 213 "exact": { 214 "type": "string" 215 }, 216 "regex": { 217 "type": "string" 218 } 219 }, 220 "allOf": [ 221 { 222 "required": [ 223 "shared" 224 ], 225 "oneOf": [ 226 { 227 "not": { 228 "anyOf": [ 229 { 230 "required": [ 231 "exact" 232 ] 233 }, 234 { 235 "required": [ 236 "regex" 237 ] 238 } 239 ] 240 } 241 }, 242 { 243 "required": [ 244 "exact" 245 ] 246 }, 247 { 248 "required": [ 249 "regex" 250 ] 251 } 252 ] 253 }, 254 { 255 "oneOf": [ 256 { 257 "not": { 258 "anyOf": [ 259 { 260 "required": [ 261 "count" 262 ] 263 }, 264 { 265 "required": [ 266 "amount" 267 ] 268 } 269 ] 270 } 271 }, 272 { 273 "required": [ 274 "count" 275 ] 276 }, 277 { 278 "required": [ 279 "amount" 280 ] 281 } 282 ], 283 "required": [ 284 "shared2" 285 ] 286 } 287 ] 288 }, 289 "exclude": { 290 "type": "array", 291 "items": { 292 "type": "object", 293 "properties": { 294 "shared": { 295 "type": "integer" 296 }, 297 "shared2": { 298 "type": "integer" 299 }, 300 "count": { 301 "type": "integer" 302 }, 303 "amount": { 304 "type": "integer" 305 }, 306 "exact": { 307 "type": "string" 308 }, 309 "regex": { 310 "type": "string" 311 } 312 }, 313 "allOf": [ 314 { 315 "required": [ 316 "shared" 317 ], 318 "oneOf": [ 319 { 320 "not": { 321 "anyOf": [ 322 { 323 "required": [ 324 "exact" 325 ] 326 }, 327 { 328 "required": [ 329 "regex" 330 ] 331 } 332 ] 333 } 334 }, 335 { 336 "required": [ 337 "exact" 338 ] 339 }, 340 { 341 "required": [ 342 "regex" 343 ] 344 } 345 ] 346 }, 347 { 348 "oneOf": [ 349 { 350 "not": { 351 "anyOf": [ 352 { 353 "required": [ 354 "count" 355 ] 356 }, 357 { 358 "required": [ 359 "amount" 360 ] 361 } 362 ] 363 } 364 }, 365 { 366 "required": [ 367 "count" 368 ] 369 }, 370 { 371 "required": [ 372 "amount" 373 ] 374 } 375 ], 376 "required": [ 377 "shared2" 378 ] 379 } 380 ] 381 } 382 }, 383 "count": { 384 "type": "integer" 385 } 386 } 387 }, 388 "Incompatible": { 389 "type": "object", 390 "properties": { 391 "shared": { 392 "type": "integer" 393 }, 394 "extra1": { 395 "type": "integer" 396 }, 397 "extra2": { 398 "type": "integer" 399 } 400 }, 401 "oneOf": [ 402 { 403 "allOf": [ 404 { 405 "required": [ 406 "shared" 407 ] 408 }, 409 { 410 "not": { 411 "anyOf": [ 412 { 413 "required": [ 414 "shared", 415 "extra1" 416 ] 417 }, 418 { 419 "required": [ 420 "shared", 421 "extra2" 422 ] 423 } 424 ] 425 } 426 } 427 ] 428 }, 429 { 430 "required": [ 431 "shared", 432 "extra1" 433 ] 434 }, 435 { 436 "required": [ 437 "shared", 438 "extra2" 439 ] 440 } 441 ] 442 }, 443 "MyInt": { 444 "type": "integer" 445 }, 446 "T": { 447 "description": "This should be dedupped.", 448 "type": "object", 449 "properties": { 450 "shared": { 451 "type": "integer" 452 }, 453 "shared2": { 454 "type": "integer" 455 }, 456 "count": { 457 "type": "integer" 458 }, 459 "amount": { 460 "type": "integer" 461 }, 462 "exact": { 463 "type": "string" 464 }, 465 "regex": { 466 "type": "string" 467 } 468 }, 469 "allOf": [ 470 { 471 "required": [ 472 "shared" 473 ], 474 "oneOf": [ 475 { 476 "not": { 477 "anyOf": [ 478 { 479 "required": [ 480 "exact" 481 ] 482 }, 483 { 484 "required": [ 485 "regex" 486 ] 487 } 488 ] 489 } 490 }, 491 { 492 "required": [ 493 "exact" 494 ] 495 }, 496 { 497 "required": [ 498 "regex" 499 ] 500 } 501 ] 502 }, 503 { 504 "oneOf": [ 505 { 506 "not": { 507 "anyOf": [ 508 { 509 "required": [ 510 "count" 511 ] 512 }, 513 { 514 "required": [ 515 "amount" 516 ] 517 } 518 ] 519 } 520 }, 521 { 522 "required": [ 523 "count" 524 ] 525 }, 526 { 527 "required": [ 528 "amount" 529 ] 530 } 531 ], 532 "required": [ 533 "shared2" 534 ] 535 } 536 ] 537 }, 538 "WithMap": { 539 "type": "object", 540 "properties": { 541 "shared": {}, 542 "extra": { 543 "type": "integer" 544 } 545 }, 546 "oneOf": [ 547 { 548 "allOf": [ 549 { 550 "required": [ 551 "shared" 552 ] 553 }, 554 { 555 "not": { 556 "anyOf": [ 557 { 558 "required": [ 559 "shared", 560 "extra" 561 ] 562 } 563 ] 564 } 565 } 566 ] 567 }, 568 { 569 "allOf": [ 570 { 571 "required": [ 572 "shared", 573 "extra" 574 ] 575 }, 576 { 577 "not": { 578 "anyOf": [ 579 { 580 "required": [ 581 "shared" 582 ] 583 } 584 ] 585 } 586 } 587 ] 588 }, 589 { 590 "required": [ 591 "shared", 592 "extra" 593 ] 594 } 595 ] 596 } 597 } 598 } 599 }