|
9 | 9 | import io.swagger.v3.oas.models.PathItem;
|
10 | 10 | import io.swagger.v3.oas.models.media.ArraySchema;
|
11 | 11 | import io.swagger.v3.oas.models.media.Content;
|
| 12 | +import io.swagger.v3.oas.models.media.IntegerSchema; |
12 | 13 | import io.swagger.v3.oas.models.media.MediaType;
|
13 | 14 | import io.swagger.v3.oas.models.media.ObjectSchema;
|
14 | 15 | import io.swagger.v3.oas.models.media.Schema;
|
@@ -426,6 +427,111 @@ public void testInlineResponseModelWithTitle() throws Exception {
|
426 | 427 | assertTrue(model.getProperties().get("name") instanceof StringSchema);
|
427 | 428 | }
|
428 | 429 |
|
| 430 | + @Test |
| 431 | + public void testSkipInlineMatchesFalse() { |
| 432 | + final OpenAPI openAPI = new OpenAPI(); |
| 433 | + |
| 434 | + final InlineModelResolver inlineModelResolver = new InlineModelResolver(); |
| 435 | + inlineModelResolver.setSkipMatches(false); |
| 436 | + |
| 437 | + final Schema operationAlphaInAsset = new ObjectSchema(); |
| 438 | + operationAlphaInAsset.setTitle("operationAlphaInAsset"); |
| 439 | + operationAlphaInAsset.addProperties("id1", new IntegerSchema()); |
| 440 | + operationAlphaInAsset.addProperties("id2", new IntegerSchema()); |
| 441 | + |
| 442 | + final Schema operationAlphaIn = new ObjectSchema(); |
| 443 | + operationAlphaIn.setTitle("operationAlphaIn"); |
| 444 | + operationAlphaIn.addProperties("asset", operationAlphaInAsset); |
| 445 | + |
| 446 | + final Schema operationAlphaRequest = new ObjectSchema(); |
| 447 | + operationAlphaRequest.setTitle("operationAlphaRequest"); |
| 448 | + operationAlphaRequest.addProperties("in", operationAlphaIn); |
| 449 | + |
| 450 | + final Schema operationBetaInAsset = new ObjectSchema(); |
| 451 | + operationBetaInAsset.setTitle("operationBetaInAsset"); |
| 452 | + operationBetaInAsset.addProperties("id1", new IntegerSchema()); |
| 453 | + operationBetaInAsset.addProperties("id2", new IntegerSchema()); |
| 454 | + |
| 455 | + final Schema operationBetaIn = new ObjectSchema(); |
| 456 | + operationBetaIn.setTitle("operationBetaIn"); |
| 457 | + operationBetaIn.addProperties("asset", operationBetaInAsset); |
| 458 | + |
| 459 | + final Schema operationBetaRequest = new ObjectSchema(); |
| 460 | + operationBetaRequest.setTitle("operationBetaRequest"); |
| 461 | + operationBetaRequest.addProperties("in", operationBetaIn); |
| 462 | + |
| 463 | + openAPI.path("/operationAlpha", new PathItem() |
| 464 | + .get(new Operation() |
| 465 | + .requestBody(new RequestBody() |
| 466 | + .content(new Content().addMediaType("*/*", new MediaType() |
| 467 | + .schema(operationAlphaRequest)))))); |
| 468 | + |
| 469 | + openAPI.path("/operationBeta", new PathItem() |
| 470 | + .get(new Operation() |
| 471 | + .requestBody(new RequestBody() |
| 472 | + .content(new Content().addMediaType("*/*", new MediaType() |
| 473 | + .schema(operationBetaRequest)))))); |
| 474 | + |
| 475 | + inlineModelResolver.flatten(openAPI); |
| 476 | + |
| 477 | + assertNotNull(openAPI); |
| 478 | + assertNotNull(openAPI.getComponents()); |
| 479 | + assertNotNull(openAPI.getComponents().getSchemas()); |
| 480 | + assertEquals(4, openAPI.getComponents().getSchemas().size()); |
| 481 | + } |
| 482 | + |
| 483 | + @Test |
| 484 | + public void testSkipInlineMatchesTrue() { |
| 485 | + final OpenAPI openAPI = new OpenAPI(); |
| 486 | + |
| 487 | + final InlineModelResolver inlineModelResolver = new InlineModelResolver(); |
| 488 | + inlineModelResolver.setSkipMatches(true); |
| 489 | + |
| 490 | + final Schema operationAlphaInAsset = new ObjectSchema(); |
| 491 | + operationAlphaInAsset.setTitle("operationAlphaInAsset"); |
| 492 | + operationAlphaInAsset.addProperties("id1", new IntegerSchema()); |
| 493 | + operationAlphaInAsset.addProperties("id2", new IntegerSchema()); |
| 494 | + |
| 495 | + final Schema operationAlphaIn = new ObjectSchema(); |
| 496 | + operationAlphaIn.setTitle("operationAlphaIn"); |
| 497 | + operationAlphaIn.addProperties("asset", operationAlphaInAsset); |
| 498 | + |
| 499 | + final Schema operationAlphaRequest = new ObjectSchema(); |
| 500 | + operationAlphaRequest.setTitle("operationAlphaRequest"); |
| 501 | + operationAlphaRequest.addProperties("in", operationAlphaIn); |
| 502 | + |
| 503 | + final Schema operationBetaInAsset = new ObjectSchema(); |
| 504 | + operationBetaInAsset.setTitle("operationBetaInAsset"); |
| 505 | + operationBetaInAsset.addProperties("id1", new IntegerSchema()); |
| 506 | + operationBetaInAsset.addProperties("id2", new IntegerSchema()); |
| 507 | + |
| 508 | + final Schema operationBetaIn = new ObjectSchema(); |
| 509 | + operationBetaIn.setTitle("operationBetaIn"); |
| 510 | + operationBetaIn.addProperties("asset", operationBetaInAsset); |
| 511 | + |
| 512 | + final Schema operationBetaRequest = new ObjectSchema(); |
| 513 | + operationBetaRequest.setTitle("operationBetaRequest"); |
| 514 | + operationBetaRequest.addProperties("in", operationBetaIn); |
| 515 | + |
| 516 | + openAPI.path("/operationAlpha", new PathItem() |
| 517 | + .get(new Operation() |
| 518 | + .requestBody(new RequestBody() |
| 519 | + .content(new Content().addMediaType("*/*", new MediaType() |
| 520 | + .schema(operationAlphaRequest)))))); |
| 521 | + |
| 522 | + openAPI.path("/operationBeta", new PathItem() |
| 523 | + .get(new Operation() |
| 524 | + .requestBody(new RequestBody() |
| 525 | + .content(new Content().addMediaType("*/*", new MediaType() |
| 526 | + .schema(operationBetaRequest)))))); |
| 527 | + |
| 528 | + inlineModelResolver.flatten(openAPI); |
| 529 | + |
| 530 | + assertNotNull(openAPI); |
| 531 | + assertNotNull(openAPI.getComponents()); |
| 532 | + assertNotNull(openAPI.getComponents().getSchemas()); |
| 533 | + assertEquals(6, openAPI.getComponents().getSchemas().size()); |
| 534 | + } |
429 | 535 |
|
430 | 536 | @Test
|
431 | 537 | public void resolveInlineArrayModelWithTitle() throws Exception {
|
|
0 commit comments