Skip to content

Commit 165465a

Browse files
[rust] Fix array enums for generated object types (#23279)
* [rust] Fix array enums for generated object types * [rust] Fix incorrect object ref notation in test YAML
1 parent f1bb59c commit 165465a

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public CodegenModel fromModel(String name, Schema model) {
300300
// If the type is an array, extend the name with the inner type to prevent name collisions
301301
// in case multiple arrays with different types are defined. If the user has manually specified
302302
// a name, use that name instead.
303-
String collectionWithTypeName = toModelName(schema.getType()) + oneOf.containerTypeMapped + oneOf.items.dataType;
303+
String collectionWithTypeName = toModelName(schema.getType()) + oneOf.containerTypeMapped + oneOf.items.baseType;
304304
String oneOfName = Optional.ofNullable(schema.getTitle()).orElse(collectionWithTypeName);
305305
oneOf.setName(oneOfName);
306306
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustClientCodegenTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,23 @@ public void testMultipleArrayTypesEnum() throws IOException {
271271
TestUtils.assertFileExists(outputPath);
272272
TestUtils.assertFileContains(outputPath, enumSpec);
273273
}
274+
275+
@Test
276+
public void testArrayWithObjectEnumValues() throws IOException {
277+
Path target = Files.createTempDirectory("test");
278+
target.toFile().deleteOnExit();
279+
final CodegenConfigurator configurator = new CodegenConfigurator()
280+
.setGeneratorName("rust")
281+
.setInputSpec("src/test/resources/3_1/issue_23278.yaml")
282+
.setSkipOverwrite(false)
283+
.setOutputDir(target.toAbsolutePath().toString().replace("\\", "/"));
284+
new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
285+
Path outputPath = Path.of(target.toString(), "/src/models/object_arrays_options.rs");
286+
String enumSpec = linearize("pub enum ObjectArraysOptions { " +
287+
"ArrayVecTestObject(Vec<models::TestObject>), " +
288+
"ArrayVecTestArray(Vec<models::TestArray>)," +
289+
"}");
290+
TestUtils.assertFileExists(outputPath);
291+
TestUtils.assertFileContains(outputPath, enumSpec);
292+
}
274293
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: 3.1.0
2+
info:
3+
title: oneOf with object arrays
4+
description: Support object types in oneOf array enums.
5+
version: 1.0.0
6+
components:
7+
schemas:
8+
ObjectArrays:
9+
type: object
10+
properties:
11+
Options:
12+
oneOf:
13+
- type: array
14+
items:
15+
$ref: '#/components/schemas/TestObject'
16+
- type: array
17+
items:
18+
$ref: '#/components/schemas/TestArray'
19+
TestObject:
20+
type: object
21+
properties:
22+
test:
23+
type: string
24+
TestArray:
25+
properties:
26+
test:
27+
type: array
28+
items:
29+
type: string

0 commit comments

Comments
 (0)