GERONIMO-6693 ensure arrays are mapped in schema when resolving it implicitly
authorRomain Manni-Bucau <rmannibucau@gmail.com>
Mon, 11 Feb 2019 13:41:11 +0000 (14:41 +0100)
committerRomain Manni-Bucau <rmannibucau@gmail.com>
Mon, 11 Feb 2019 13:41:11 +0000 (14:41 +0100)
geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/SchemaProcessor.java
geronimo-openapi-impl/src/test/java/org/apache/geronimo/microprofile/openapi/impl/processor/SchemaProcessorTest.java

index ff94b93..45e54f5 100644 (file)
@@ -98,8 +98,13 @@ public class SchemaProcessor {
                 final Class from = Class.class.cast(model);
                 if (from.isEnum()) {
                     schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.STRING)
-                                 .enumeration(asList(from.getEnumConstants()))
-                                 .nullable(true);
+                          .enumeration(asList(from.getEnumConstants()))
+                          .nullable(true);
+                } else if (from.isArray()) {
+                    schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
+                    final SchemaImpl items = new SchemaImpl();
+                    fillSchema(components, from.getComponentType(), items, null);
+                    schema.items(items);
                 } else {
                     ofNullable(from.getAnnotation(Schema.class)).ifPresent(
                             s -> sets(components, Schema.class.cast(s), schema, null));
index 6b05270..50ef826 100644 (file)
@@ -72,6 +72,16 @@ public class SchemaProcessorTest {
         assertEquals(Stream.of("simple", "child", "children").collect(toSet()), completeSchema.getProperties().keySet());
     }
 
+    @Test
+    public void array() {
+        final Components components = new ComponentsImpl();
+        final Schema schema = new SchemaProcessor().mapSchemaFromClass(() -> components, SomeClassWithArray.class);
+        assertEquals(1, schema.getProperties().size());
+        final Schema array = schema.getProperties().get("thearray");
+        assertEquals(Schema.SchemaType.ARRAY, array.getType());
+        assertEquals(Schema.SchemaType.STRING, array.getItems().getType());
+    }
+
     private Supplier<Components> newComponentsProvider() {
         final ComponentsImpl components = new ComponentsImpl();
         return () -> components;
@@ -102,6 +112,10 @@ public class SchemaProcessorTest {
         private List<SomeRelatedClass> children;
     }
 
+    public static class SomeClassWithArray {
+        private String[] thearray;
+    }
+
     public static class DataWithEnum {
         private AnEnum anEnum;
     }