Repository: juhaku/utoipa (Rust)

Issue:
Can't inline struct field with Vec<Foo>
Inlining a struct field like:

```rust
struct Bar {
    #[component(inline)]
    foo: Vec<Foo>
}
```

results in the following error:

```text
no method named `to_array_builder` found for enum `utoipa::openapi::Component` in the current scope
```


Discussion:

Patch:
diff --git a/utoipa-gen/src/path/property.rs b/utoipa-gen/src/path/property.rs
index 53ec62fd..51e80879 100644
--- a/utoipa-gen/src/path/property.rs
+++ b/utoipa-gen/src/path/property.rs
@@ -40,13 +40,14 @@ impl ToTokens for Property<'_> {
                 })
             }
 
-            if self.type_definition.is_array {
-                component.extend(quote! {
-                    .to_array_builder()
-                });
-            }
-
-            tokens.extend(component);
+            tokens.extend(if self.type_definition.is_array {
+                quote! {
+                    utoipa::openapi::schema::ArrayBuilder::new()
+                        .items(#component)
+                }
+            } else {
+                component
+            });
         } else {
             let component_name_ident: &Ident = &*component_type.0;
             let name = component_name_ident.to_string();
@@ -56,16 +57,14 @@ impl ToTokens for Property<'_> {
                     <#component_name_ident as utoipa::Component>::component()
                 };
 
-                if self.type_definition.is_array {
-                    let array_component = quote! {
+                tokens.extend(if self.type_definition.is_array {
+                    quote! {
                         utoipa::openapi::schema::ArrayBuilder::new()
                             .items(#component)
-                    };
-
-                    tokens.extend(array_component);
+                    }
                 } else {
-                    tokens.extend(component);
-                }
+                    component
+                });
             } else {
                 tokens.extend(quote! {
                     utoipa::openapi::Ref::from_component_name(#name)
diff --git a/utoipa-gen/src/schema/component.rs b/utoipa-gen/src/schema/component.rs
index 59ba64bf..92abddaf 100644
--- a/utoipa-gen/src/schema/component.rs
+++ b/utoipa-gen/src/schema/component.rs
@@ -715,7 +715,8 @@ where
 
                 if self.type_override.is_none() {
                     tokens.extend(quote! {
-                        #component_property.to_array_builder()
+                        utoipa::openapi::schema::ArrayBuilder::new()
+                            .items(#component_property)
                     });
 
                     if let Some(xml_value) = self.xml {


Test patch:
diff --git a/tests/component_derive_test.rs b/tests/component_derive_test.rs
index 91a63213..352ad4d9 100644
--- a/tests/component_derive_test.rs
+++ b/tests/component_derive_test.rs
@@ -508,7 +508,7 @@ fn derive_with_box_and_refcell() {
 }
 
 #[test]
-fn derive_with_inline() {
+fn derive_struct_with_inline() {
     #[derive(utoipa::Component)]
     #[allow(unused)]
     struct Foo {
@@ -523,6 +523,8 @@ fn derive_with_inline() {
             foo2: Option<Foo>,
             #[component(inline)]
             foo3: Option<Box<Foo>>,
+            #[component(inline)]
+            foo4: Vec<Foo>,
         }
     };
 
@@ -563,9 +565,24 @@ fn derive_with_inline() {
                     ],
                     "type": "object"
                 },
+                "foo4": {
+                    "items": {
+                        "properties": {
+                            "name": {
+                                "type": "string"
+                            },
+                        },
+                        "required": [
+                            "name"
+                        ],
+                        "type": "object"
+                    },
+                    "type": "array"
+                },
             },
             "required": [
-                "foo1"
+                "foo1",
+                "foo4",
             ],
             "type": "object"
         })