|
27 | 27 | import org.testng.annotations.Test; |
28 | 28 |
|
29 | 29 | import java.math.BigDecimal; |
| 30 | +import java.util.ArrayList; |
30 | 31 | import java.util.Arrays; |
31 | 32 | import java.util.HashMap; |
32 | 33 | import java.util.List; |
@@ -582,6 +583,38 @@ public void simplifyAnyOfWithOnlyOneNonNullSubSchemaKeepsReadOnlyWriteOnlyAttrib |
582 | 583 | assertEquals(schema.get$ref(), "#/components/schemas/IntegerRef"); |
583 | 584 | } |
584 | 585 |
|
| 586 | + @Test |
| 587 | + public void simplifyOneOfAnyOfWithOnlyOneNonNullSubSchemaKeepsParentDescription() { |
| 588 | + OpenAPI openAPI = new OpenAPI(); |
| 589 | + |
| 590 | + Schema anyOfParent = new Schema().description("Access token"); |
| 591 | + anyOfParent.setAnyOf(new ArrayList<>(Arrays.asList( |
| 592 | + new StringSchema(), |
| 593 | + new Schema<>().type("null") |
| 594 | + ))); |
| 595 | + Schema anyOfSchema = ModelUtils.simplifyOneOfAnyOfWithOnlyOneNonNullSubSchema(openAPI, anyOfParent, anyOfParent.getAnyOf()); |
| 596 | + assertEquals(anyOfSchema.getDescription(), "Access token"); |
| 597 | + |
| 598 | + Schema oneOfParent = new Schema().description("Expires at"); |
| 599 | + oneOfParent.setOneOf(new ArrayList<>(Arrays.asList( |
| 600 | + new IntegerSchema(), |
| 601 | + new Schema<>().type("null") |
| 602 | + ))); |
| 603 | + Schema oneOfSchema = ModelUtils.simplifyOneOfAnyOfWithOnlyOneNonNullSubSchema(openAPI, oneOfParent, oneOfParent.getOneOf()); |
| 604 | + assertEquals(oneOfSchema.getDescription(), "Expires at"); |
| 605 | + |
| 606 | + Schema anyOfParentWithChildDescription = new Schema().description("Parent description"); |
| 607 | + anyOfParentWithChildDescription.setAnyOf(new ArrayList<>(Arrays.asList( |
| 608 | + new StringSchema().description("Child description"), |
| 609 | + new Schema<>().type("null") |
| 610 | + ))); |
| 611 | + Schema anyOfSchemaWithChildDescription = ModelUtils.simplifyOneOfAnyOfWithOnlyOneNonNullSubSchema( |
| 612 | + openAPI, |
| 613 | + anyOfParentWithChildDescription, |
| 614 | + anyOfParentWithChildDescription.getAnyOf()); |
| 615 | + assertEquals(anyOfSchemaWithChildDescription.getDescription(), "Child description"); |
| 616 | + } |
| 617 | + |
585 | 618 | @Test |
586 | 619 | public void isNullTypeSchemaTest() { |
587 | 620 | OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/null_schema_test.yaml"); |
|
0 commit comments