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..5d25f7f5ba5f --- /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: + $ref: '#/components/schemas/TestObject' + - type: array + items: + $ref: '#/components/schemas/TestArray' + TestObject: + type: object + properties: + test: + type: string + TestArray: + properties: + test: + type: array + items: + type: string