From 253f4c64bd5c7e8a1ff205d3747fdc47ae287152 Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Tue, 17 Mar 2026 22:44:52 +0100 Subject: [PATCH 1/2] [rust] Fix array enums for generated object types --- .../codegen/languages/RustClientCodegen.java | 2 +- .../codegen/rust/RustClientCodegenTest.java | 19 ++++++++++++ .../src/test/resources/3_1/issue_23278.yaml | 29 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index 98d5def4a85d..b90a1d98cf73 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -300,7 +300,7 @@ public CodegenModel fromModel(String name, Schema model) { // If the type is an array, extend the name with the inner type to prevent name collisions // in case multiple arrays with different types are defined. If the user has manually specified // a name, use that name instead. - String collectionWithTypeName = toModelName(schema.getType()) + oneOf.containerTypeMapped + oneOf.items.dataType; + String collectionWithTypeName = toModelName(schema.getType()) + oneOf.containerTypeMapped + oneOf.items.baseType; String oneOfName = Optional.ofNullable(schema.getTitle()).orElse(collectionWithTypeName); oneOf.setName(oneOfName); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java index c092ad3d7aeb..a73e8773387a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java @@ -271,4 +271,23 @@ public void testMultipleArrayTypesEnum() throws IOException { TestUtils.assertFileExists(outputPath); TestUtils.assertFileContains(outputPath, enumSpec); } + + @Test + public void testArrayWithObjectEnumValues() throws IOException { + Path target = Files.createTempDirectory("test"); + target.toFile().deleteOnExit(); + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("rust") + .setInputSpec("src/test/resources/3_1/issue_23278.yaml") + .setSkipOverwrite(false) + .setOutputDir(target.toAbsolutePath().toString().replace("\\", "/")); + new DefaultGenerator().opts(configurator.toClientOptInput()).generate(); + Path outputPath = Path.of(target.toString(), "/src/models/object_arrays_options.rs"); + String enumSpec = linearize("pub enum ObjectArraysOptions { " + + "ArrayVecTestObject(Vec), " + + "ArrayVecTestArray(Vec)," + + "}"); + TestUtils.assertFileExists(outputPath); + TestUtils.assertFileContains(outputPath, enumSpec); + } } diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml new file mode 100644 index 000000000000..a0782d541515 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml @@ -0,0 +1,29 @@ +openapi: 3.1.0 +info: + title: oneOf with object arrays + description: Support object types in oneOf array enums. + version: 1.0.0 +components: + schemas: + ObjectArrays: + type: object + properties: + Options: + oneOf: + - type: array + items: + type: TestObject + - type: array + items: + type: TestArray + TestObject: + type: object + properties: + test: + type: string + TestArray: + properties: + test: + type: array + items: + type: string From 60203810a94988fc7922d842b5facbf7e428a40d Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Tue, 17 Mar 2026 23:11:35 +0100 Subject: [PATCH 2/2] [rust] Fix incorrect object ref notation in test YAML --- .../openapi-generator/src/test/resources/3_1/issue_23278.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml index a0782d541515..5d25f7f5ba5f 100644 --- a/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml @@ -12,10 +12,10 @@ components: oneOf: - type: array items: - type: TestObject + $ref: '#/components/schemas/TestObject' - type: array items: - type: TestArray + $ref: '#/components/schemas/TestArray' TestObject: type: object properties: