Skip to content

Commit 48590d7

Browse files
committed
fix
1 parent ec5401b commit 48590d7

2 files changed

Lines changed: 14 additions & 34 deletions

File tree

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,13 @@ private void processNestedSchemas(Schema schema, Set<Schema> visitedSchemas) {
443443
List<Schema> newOneOfs = new ArrayList<>();
444444
for (Schema oneOf : oneOfs) {
445445
Schema oneOfSchema = oneOf;
446-
if (ModelUtils.isAllOf(oneOf) && oneOf.getAllOf() != null && !oneOf.getAllOf().isEmpty()) {
447-
if (oneOf.getAllOf().size() == 1) {
448-
Object allOfObj = oneOf.getAllOf().get(0);
449-
if (allOfObj instanceof Schema) {
450-
Schema allOfItem = (Schema) allOfObj;
451-
if (StringUtils.isNotEmpty(allOfItem.get$ref())) {
452-
oneOfSchema = ModelUtils.getReferencedSchema(openAPI, allOfItem);
453-
}
446+
if (ModelUtils.isAllOf(oneOf) && oneOf.getAllOf() != null && oneOf.getAllOf().size() == 1) {
447+
Object allOfObj = oneOf.getAllOf().get(0);
448+
if (allOfObj instanceof Schema) {
449+
Schema allOfItem = (Schema) allOfObj;
450+
if (StringUtils.isNotEmpty(allOfItem.get$ref())) {
451+
oneOfSchema = ModelUtils.getReferencedSchema(openAPI, allOfItem);
454452
}
455-
} else {
456-
LOGGER.warn("oneOf item has allOf with multiple items, which is not supported.");
457453
}
458454
} else {
459455
oneOfSchema = ModelUtils.getReferencedSchema(openAPI, oneOf);

modules/openapi-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.Arrays;
4747
import java.util.List;
4848
import java.util.Map;
49-
import java.util.HashMap;
5049

5150

5251
import static org.openapitools.codegen.TestUtils.createCodegenModelWrapper;
@@ -102,38 +101,23 @@ private void assertFileEquals(Path generatedFilePath, Path expectedFilePath) thr
102101
public void testCodeGenWithPrimitiveOneOf() throws IOException {
103102
// set line break to \n across all platforms
104103
System.setProperty("line.separator", "\n");
105-
Map<String, String> importmapping = new HashMap<>();
106-
Map<String, String> typemapping = new HashMap<>();
107-
typemapping.put("AnyType", "ObjectMap");
108-
typemapping.put("object", "ObjectMap");
109-
typemapping.put("bytes", "bytes");
110-
typemapping.put("NullValue", "NullValue");
111-
typemapping.put("number", "GeneralNumber");
104+
112105
File output = Files.createTempDirectory("test").toFile();
113-
Map<String, Object> additionalProperties = new HashMap<>();
114-
additionalProperties.put("numberedFieldNumberList", true);
115-
additionalProperties.put("aggregateModelsName", "aaaa");
116-
additionalProperties.put("supportMultipleResponses", false);
117-
Map<String, String> inline = new HashMap<>();
118-
Map<String, String> globalProperty = new HashMap<>();
119-
globalProperty.put("skipFormModel", "true");
120-
inline.put("RESOLVE_INLINE_ENUMS", "true");
121-
inline.put("SKIP_SCHEMA_REUSE", "true");
106+
122107
final CodegenConfigurator configurator = new CodegenConfigurator()
123108
.setGeneratorName("protobuf-schema")
124109
.setInputSpec("src/test/resources/3_0/oneOf.yaml")
125-
.setAdditionalProperties(additionalProperties)
126-
.setTypeMappings(typemapping)
127-
.setImportMappings(importmapping)
128-
.setGlobalProperties(globalProperty)
129-
.setInlineSchemaOptions(inline)
130-
.setValidateSpec(false)
131-
.setOutputDir("/home/user/openapi-generator/test/");
110+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
132111

133112
final ClientOptInput clientOptInput = configurator.toClientOptInput();
134113
DefaultGenerator generator = new DefaultGenerator();
135114
List<File> files = generator.opts(clientOptInput).generate();
136115

116+
TestUtils.ensureContainsFile(files, output, "models/fruit.proto");
117+
Path path = Paths.get(output + "/models/fruit.proto");
118+
119+
assertFileEquals(path, Paths.get("src/test/resources/3_0/protobuf-schema/fruitOneOf.proto"));
120+
137121
output.deleteOnExit();
138122
}
139123

0 commit comments

Comments
 (0)