Skip to content
Merged
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 @@ -288,7 +288,15 @@ public CodegenModel fromModel(String name, Schema model) {
oneOf.setName(modelName);
oneOf.setBaseName(refName);
}
} else {
} else if (oneOf.isArray) {
// 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 oneOfName = Optional.ofNullable(schema.getTitle()).orElse(collectionWithTypeName);
oneOf.setName(oneOfName);
}
else {
// In-placed type (primitive), because there is no mapping or ref for it.
// use camelized `title` if present, otherwise use `type`
String oneOfName = Optional.ofNullable(schema.getTitle()).orElseGet(schema::getType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@

import io.swagger.v3.oas.models.media.IntegerSchema;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.TestUtils;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.languages.RustClientCodegen;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static org.openapitools.codegen.TestUtils.linearize;

public class RustClientCodegenTest {

Expand Down Expand Up @@ -243,4 +253,22 @@ public void testWithIntegerFittingAndPreferUnsigned() {
Assert.assertEquals(codegen.getSchemaType(s), "i64");
}

@Test
public void testMultipleArrayTypesEnum() throws IOException {
Path target = Files.createTempDirectory("test");
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("rust")
.setInputSpec("src/test/resources/3_1/issue_18527.yaml")
.setSkipOverwrite(false)
.setOutputDir(target.toAbsolutePath().toString().replace("\\", "/"));
List<File> files = new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
files.forEach(File::deleteOnExit);
Path outputPath = Path.of(target.toString(), "/src/models/option1_or_option2_options.rs");
String enumSpec = linearize("pub enum Option1OrOption2Options { " +
"ArrayVecString(Vec<String>), " +
"ArrayVeci32(Vec<i32>)," +
"}");
TestUtils.assertFileExists(outputPath);
TestUtils.assertFileContains(outputPath, enumSpec);
}
}
19 changes: 19 additions & 0 deletions modules/openapi-generator/src/test/resources/3_1/issue_18527.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.1.0
info:
title: oneOf with arrays
description: Ensure different names for kinds in enum when using oneOf with arrays.
version: 1.0.0
paths: {}
components:
schemas:
Option1OrOption2:
type: object
properties:
Options:
oneOf:
- type: array
items:
type: string
- type: array
items:
type: integer
Loading