|
279 | 279 | "valid": false |
280 | 280 | } |
281 | 281 | ] |
| 282 | + }, |
| 283 | + { |
| 284 | + "description": "Issue #398 - $ref pointing to base type with discriminator and w/o anyOf", |
| 285 | + "schema": { |
| 286 | + "$ref": "#/components/schemas/Room", |
| 287 | + "components": { |
| 288 | + "schemas": { |
| 289 | + "Room": { |
| 290 | + "type": "object", |
| 291 | + "properties": { |
| 292 | + "@type": { |
| 293 | + "type": "string" |
| 294 | + }, |
| 295 | + "floor": { |
| 296 | + "type": "integer" |
| 297 | + }, |
| 298 | + "nextRoom": { |
| 299 | + "anyOf": [ |
| 300 | + {"$ref":"#/components/schemas/Room" }, |
| 301 | + {"$ref":"#/components/schemas/BedRoom" } |
| 302 | + ] |
| 303 | + } |
| 304 | + }, |
| 305 | + "required": [ |
| 306 | + "@type" |
| 307 | + ], |
| 308 | + "discriminator": { |
| 309 | + "propertyName": "@type" |
| 310 | + } |
| 311 | + }, |
| 312 | + "BedRoom": { |
| 313 | + "type": "object", |
| 314 | + "allOf": [ |
| 315 | + { |
| 316 | + "$ref": "#/components/schemas/Room" |
| 317 | + }, |
| 318 | + { |
| 319 | + "type": "object", |
| 320 | + "properties": { |
| 321 | + "numberOfBeds": { |
| 322 | + "type": "integer" |
| 323 | + } |
| 324 | + }, |
| 325 | + "required": [ |
| 326 | + "numberOfBeds" |
| 327 | + ] |
| 328 | + } |
| 329 | + ] |
| 330 | + } |
| 331 | + } |
| 332 | + } |
| 333 | + }, |
| 334 | + "tests": [ |
| 335 | + { |
| 336 | + "description": "$ref without anyOf and therefore no discriminator context", |
| 337 | + "data": { |
| 338 | + "@type": "Room" |
| 339 | + }, |
| 340 | + "valid": true |
| 341 | + }, |
| 342 | + { |
| 343 | + "description": "schema with discriminator and recursion with invalid BedRoom", |
| 344 | + "data": { |
| 345 | + "@type": "can be ignored - discriminator not in use on root schema", |
| 346 | + "numberOfBeds": 42, |
| 347 | + "nextRoom": { |
| 348 | + "@type": "BedRoom", |
| 349 | + "floor": 1 |
| 350 | + } |
| 351 | + }, |
| 352 | + "valid": false |
| 353 | + } |
| 354 | + ] |
| 355 | + }, |
| 356 | + { |
| 357 | + "description": "Issue #398 - $ref pointing to extended type with discriminator and w/o anyOf", |
| 358 | + "schema": { |
| 359 | + "$ref": "#/components/schemas/BedRoom", |
| 360 | + "components": { |
| 361 | + "schemas": { |
| 362 | + "Room": { |
| 363 | + "type": "object", |
| 364 | + "properties": { |
| 365 | + "@type": { |
| 366 | + "type": "string" |
| 367 | + }, |
| 368 | + "floor": { |
| 369 | + "type": "integer" |
| 370 | + }, |
| 371 | + "nextRoom": { |
| 372 | + "anyOf": [ |
| 373 | + {"$ref": "#/components/schemas/Room"}, |
| 374 | + {"$ref": "#/components/schemas/BedRoom"} |
| 375 | + ] |
| 376 | + } |
| 377 | + }, |
| 378 | + "required": [ |
| 379 | + "@type" |
| 380 | + ], |
| 381 | + "discriminator": { |
| 382 | + "propertyName": "@type" |
| 383 | + } |
| 384 | + }, |
| 385 | + "BedRoom": { |
| 386 | + "type": "object", |
| 387 | + "allOf": [ |
| 388 | + { |
| 389 | + "$ref": "#/components/schemas/Room" |
| 390 | + }, |
| 391 | + { |
| 392 | + "type": "object", |
| 393 | + "properties": { |
| 394 | + "numberOfBeds": { |
| 395 | + "type": "integer" |
| 396 | + }, |
| 397 | + "nextRoom": { |
| 398 | + "anyOf": [ |
| 399 | + {"$ref": "#/components/schemas/Room"}, |
| 400 | + {"$ref": "#/components/schemas/BedRoom"} |
| 401 | + ] |
| 402 | + } |
| 403 | + }, |
| 404 | + "required": [ |
| 405 | + "numberOfBeds" |
| 406 | + ] |
| 407 | + } |
| 408 | + ] |
| 409 | + } |
| 410 | + } |
| 411 | + } |
| 412 | + }, |
| 413 | + "tests": [ |
| 414 | + { |
| 415 | + "description": "$ref without anyOf and therefore no discriminator context", |
| 416 | + "data": { |
| 417 | + "@type": "can be ignored - discriminator not in use on root schema", |
| 418 | + "numberOfBeds": 42, |
| 419 | + "nextRoom": { |
| 420 | + "@type": "Room", |
| 421 | + "floor": 3 |
| 422 | + } |
| 423 | + }, |
| 424 | + "valid": true |
| 425 | + }, |
| 426 | + { |
| 427 | + "description": "schema with discriminator and recursion with valid BedRoom", |
| 428 | + "data": { |
| 429 | + "@type": "can be ignored - discriminator not in use on root schema", |
| 430 | + "numberOfBeds": 42, |
| 431 | + "nextRoom": { |
| 432 | + "@type": "BedRoom", |
| 433 | + "floor": 1, |
| 434 | + "numberOfBeds": 12345 |
| 435 | + } |
| 436 | + }, |
| 437 | + "valid": true |
| 438 | + }, |
| 439 | + { |
| 440 | + "description": "schema with discriminator and recursion with invalid BedRoom", |
| 441 | + "data": { |
| 442 | + "@type": "can be ignored - discriminator not in use on root schema", |
| 443 | + "numberOfBeds": 42, |
| 444 | + "nextRoom": { |
| 445 | + "@type": "BedRoom", |
| 446 | + "floor": 1 |
| 447 | + } |
| 448 | + }, |
| 449 | + "valid": false |
| 450 | + } |
| 451 | + ] |
| 452 | + }, |
| 453 | + { |
| 454 | + "description": "Issue #398 - invalid discriminator specification has to lead to failed validation", |
| 455 | + "schema": { |
| 456 | + "anyOf": [ |
| 457 | + {"$ref": "#/components/schemas/Room"}, |
| 458 | + {"$ref": "#/components/schemas/BedRoom"} |
| 459 | + ], |
| 460 | + "components": { |
| 461 | + "schemas": { |
| 462 | + "Room": { |
| 463 | + "type": "object", |
| 464 | + "properties": { |
| 465 | + "@type": { |
| 466 | + "type": "string" |
| 467 | + }, |
| 468 | + "floor": { |
| 469 | + "type": "integer" |
| 470 | + }, |
| 471 | + "nextRoom": { |
| 472 | + "anyOf": [ |
| 473 | + {"$ref": "#/components/schemas/Room"}, |
| 474 | + {"$ref": "#/components/schemas/BedRoom"} |
| 475 | + ] |
| 476 | + } |
| 477 | + }, |
| 478 | + "required": [ |
| 479 | + "@type" |
| 480 | + ], |
| 481 | + "discriminator": { |
| 482 | + "propertyName": "@type" |
| 483 | + } |
| 484 | + }, |
| 485 | + "BedRoom": { |
| 486 | + "type": "object", |
| 487 | + "allOf": [ |
| 488 | + { |
| 489 | + "$ref": "#/components/schemas/Room" |
| 490 | + }, |
| 491 | + { |
| 492 | + "type": "object", |
| 493 | + "properties": { |
| 494 | + "numberOfBeds": { |
| 495 | + "type": "integer" |
| 496 | + }, |
| 497 | + "nextRoom": { |
| 498 | + "anyOf": [ |
| 499 | + {"$ref": "#/components/schemas/Room"}, |
| 500 | + {"$ref": "#/components/schemas/BedRoom"} |
| 501 | + ] |
| 502 | + } |
| 503 | + }, |
| 504 | + "required": [ |
| 505 | + "numberOfBeds" |
| 506 | + ] |
| 507 | + } |
| 508 | + ] |
| 509 | + } |
| 510 | + } |
| 511 | + } |
| 512 | + }, |
| 513 | + "tests": [ |
| 514 | + { |
| 515 | + "description": "$ref without anyOf and therefore no discriminator context", |
| 516 | + "data": { |
| 517 | + "@type": "illegal discriminator property value" |
| 518 | + }, |
| 519 | + "valid": false |
| 520 | + } |
| 521 | + ] |
282 | 522 | } |
283 | 523 | ] |
0 commit comments