Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<models::TestObject>), " +
"ArrayVecTestArray(Vec<models::TestArray>)," +
"}");
TestUtils.assertFileExists(outputPath);
TestUtils.assertFileContains(outputPath, enumSpec);
}
}
29 changes: 29 additions & 0 deletions modules/openapi-generator/src/test/resources/3_1/issue_23278.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading