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