|
13 | 13 | import io.swagger.v3.core.jackson.ModelResolver; |
14 | 14 | import io.swagger.v3.core.model.ApiDescription; |
15 | 15 | import io.swagger.v3.core.util.Configuration; |
| 16 | +import io.swagger.v3.core.util.Json; |
16 | 17 | import io.swagger.v3.core.util.PrimitiveType; |
17 | 18 | import io.swagger.v3.jaxrs2.matchers.SerializationMatchers; |
18 | 19 | import io.swagger.v3.jaxrs2.petstore31.PetResource; |
|
83 | 84 | import io.swagger.v3.jaxrs2.resources.Ticket3731BisResource; |
84 | 85 | import io.swagger.v3.jaxrs2.resources.Ticket3731Resource; |
85 | 86 | import io.swagger.v3.jaxrs2.resources.Ticket4065Resource; |
| 87 | +import io.swagger.v3.jaxrs2.resources.Ticket4341Resource; |
86 | 88 | import io.swagger.v3.jaxrs2.resources.Ticket4412Resource; |
87 | 89 | import io.swagger.v3.jaxrs2.resources.Ticket4446Resource; |
88 | 90 | import io.swagger.v3.jaxrs2.resources.Ticket4483Resource; |
@@ -795,6 +797,32 @@ public void test2497() { |
795 | 797 | assertEquals(openAPI.getComponents().getSchemas().get("User").getRequired().get(0), "issue3438"); |
796 | 798 | } |
797 | 799 |
|
| 800 | + @Test(description = "array required property resolved from ArraySchema.arraySchema.requiredMode") |
| 801 | + public void test4341() { |
| 802 | + Reader reader = new Reader(new OpenAPI()); |
| 803 | + OpenAPI openAPI = reader.read(Ticket4341Resource.class); |
| 804 | + Schema userSchema = openAPI.getComponents().getSchemas().get("User"); |
| 805 | + List<String> required = userSchema.getRequired(); |
| 806 | + |
| 807 | + assertTrue(required.contains("requiredArray")); |
| 808 | + assertFalse(required.contains("notRequiredArray")); |
| 809 | + assertFalse(required.contains("notRequiredArrayWithNotNull")); |
| 810 | + assertTrue(required.contains("autoRequiredWithNotNull")); |
| 811 | + assertFalse(required.contains("autoNotRequired")); |
| 812 | + |
| 813 | + assertTrue( |
| 814 | + required.contains("requiredArrayArraySchemaOnly"), |
| 815 | + "arraySchema.requiredMode=REQUIRED should make the array property required " + |
| 816 | + "even when items schema is not explicitly provided" |
| 817 | + ); |
| 818 | + |
| 819 | + assertFalse( |
| 820 | + required.contains("requiredItemsOnlyArray"), |
| 821 | + "schema(requiredMode=REQUIRED) on items must not make the array property required; " + |
| 822 | + "requiredness is controlled by arraySchema.requiredMode" |
| 823 | + ); |
| 824 | + } |
| 825 | + |
798 | 826 | @Test(description = "test resource with subresources") |
799 | 827 | public void testResourceWithSubresources() { |
800 | 828 | Reader reader = new Reader(new OpenAPI()); |
@@ -5503,4 +5531,81 @@ public void testTicket4907() { |
5503 | 5531 | SerializationMatchers.assertEqualsToYaml31(openAPI, yaml); |
5504 | 5532 | ModelConverters.reset(); |
5505 | 5533 | } |
| 5534 | + |
| 5535 | + @Test(description = "array property metadata is resolved from ArraySchema.arraySchema, items metadata from ArraySchema.schema") |
| 5536 | + public void test4341ArraySchemaOtherAttributes() { |
| 5537 | + Reader reader = new Reader(new OpenAPI()); |
| 5538 | + OpenAPI openAPI = reader.read(Ticket4341Resource.class); |
| 5539 | + System.out.println(Json.pretty(openAPI)); |
| 5540 | + |
| 5541 | + Schema userSchema = openAPI.getComponents().getSchemas().get("User"); |
| 5542 | + assertNotNull(userSchema, "User schema should be present"); |
| 5543 | + |
| 5544 | + @SuppressWarnings("unchecked") |
| 5545 | + Map<String, Schema> properties = userSchema.getProperties(); |
| 5546 | + assertNotNull(properties, "User properties should not be null"); |
| 5547 | + |
| 5548 | + Schema metadataArray = properties.get("metadataArray"); |
| 5549 | + assertNotNull(metadataArray, "metadataArray property should be present"); |
| 5550 | + assertTrue(metadataArray instanceof ArraySchema, "metadataArray should be an ArraySchema"); |
| 5551 | + |
| 5552 | + // Property-level assertions |
| 5553 | + assertEquals( |
| 5554 | + metadataArray.getDescription(), |
| 5555 | + "array-level description", |
| 5556 | + "Array property description should come from arraySchema, not items schema" |
| 5557 | + ); |
| 5558 | + |
| 5559 | + assertEquals( |
| 5560 | + metadataArray.getDeprecated(), |
| 5561 | + Boolean.TRUE, |
| 5562 | + "Array property deprecated should come from arraySchema" |
| 5563 | + ); |
| 5564 | + |
| 5565 | + assertEquals( |
| 5566 | + metadataArray.getReadOnly(), |
| 5567 | + Boolean.TRUE, |
| 5568 | + "Array property readOnly should be true from arraySchema.accessMode=READ_ONLY" |
| 5569 | + ); |
| 5570 | + assertNotEquals( |
| 5571 | + metadataArray.getWriteOnly(), |
| 5572 | + Boolean.TRUE, |
| 5573 | + "Array property writeOnly should not be true when accessMode=READ_ONLY" |
| 5574 | + ); |
| 5575 | + |
| 5576 | + // Item-level assertions |
| 5577 | + |
| 5578 | + ArraySchema metadataArraySchema = (ArraySchema) metadataArray; |
| 5579 | + Schema items = metadataArraySchema.getItems(); |
| 5580 | + assertNotNull(items, "Items schema should not be null"); |
| 5581 | + |
| 5582 | + assertEquals( |
| 5583 | + items.getDescription(), |
| 5584 | + "item-level description", |
| 5585 | + "Items description should come from schema element of @ArraySchema" |
| 5586 | + ); |
| 5587 | + |
| 5588 | + assertNotEquals( |
| 5589 | + items.getDeprecated(), |
| 5590 | + Boolean.TRUE, |
| 5591 | + "Items deprecated should not be true when schema.deprecated=false" |
| 5592 | + ); |
| 5593 | + |
| 5594 | + assertEquals( |
| 5595 | + items.getWriteOnly(), |
| 5596 | + Boolean.TRUE, |
| 5597 | + "Items writeOnly should be true from schema.accessMode=WRITE_ONLY" |
| 5598 | + ); |
| 5599 | + assertNotEquals( |
| 5600 | + items.getReadOnly(), |
| 5601 | + Boolean.TRUE, |
| 5602 | + "Items readOnly should not be true when accessMode=WRITE_ONLY" |
| 5603 | + ); |
| 5604 | + |
| 5605 | + assertEquals( |
| 5606 | + items.getFormat(), |
| 5607 | + "email", |
| 5608 | + "Items format should come from schema.format" |
| 5609 | + ); |
| 5610 | + } |
5506 | 5611 | } |
0 commit comments