Skip to content

Commit cb462e6

Browse files
committed
fix property name of inherited model for oneOf fix imports for oneOf
1 parent 2db8477 commit cb462e6

File tree

1 file changed

+13
-43
lines changed
  • modules/openapi-generator/src/main/java/org/openapitools/codegen/languages

1 file changed

+13
-43
lines changed

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

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,10 @@ public void addOneOfInterfaceModel(ComposedSchema cs, String name) {
670670
cm.interfaceModels = new ArrayList<CodegenModel>();
671671

672672
for(Schema schema : cs.getOneOf()){
673-
cm.vars.add(fromProperty("property", schema));
673+
String singleSchemaType = getSingleSchemaType(schema);
674+
CodegenProperty codegenProperty = fromProperty(singleSchemaType, schema);
675+
codegenProperty.setBaseName(singleSchemaType.toLowerCase(Locale.getDefault()));
676+
cm.vars.add(codegenProperty);
674677
}
675678
addOneOfInterfaces.add(cm);
676679
}
@@ -721,9 +724,12 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
721724
omitAdding.add(v.baseName);
722725
}
723726
}
724-
for (CodegenProperty v : toAdd) {
725-
if (!omitAdding.contains(v.baseName)) {
726-
additionalProps.add(v.clone());
727+
for (int i = 0; i < toAdd.size(); i++) {
728+
if (!omitAdding.contains(toAdd.get(i).baseName)) {
729+
if (i != toAdd.size() - 1) {
730+
toAdd.get(i).hasMore = true;
731+
}
732+
additionalProps.add(toAdd.get(i));
727733
}
728734
}
729735

@@ -734,46 +740,8 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
734740
}
735741
}
736742

737-
public void addToImplementor(CodegenModel implcm, List<Map<String, String>> implImports) {
738-
implcm.getVendorExtensions().putIfAbsent("implements", new ArrayList<String>());
739-
740-
// Add implemented interfaces
741-
for (String intf : additionalInterfaces) {
742-
List<String> impl = (List<String>) implcm.getVendorExtensions().get("implements");
743-
impl.add(intf);
744-
// Add imports for interfaces
745-
implcm.imports.add(intf);
746-
Map<String, String> importsItem = new HashMap<String, String>();
747-
importsItem.put("import", toModelImport(intf));
748-
implImports.add(importsItem);
749-
}
750-
751-
// Add oneOf-containing models properties - we need to properly set the hasMore values to make renderind correct
752-
if (implcm.vars.size() > 0 && additionalProps.size() > 0) {
753-
implcm.vars.get(implcm.vars.size() - 1).hasMore = true;
754-
}
755-
for (int i = 0; i < additionalProps.size(); i++) {
756-
CodegenProperty var = additionalProps.get(i);
757-
if (i == additionalProps.size() - 1) {
758-
var.hasMore = false;
759-
} else {
760-
var.hasMore = true;
761-
}
762-
implcm.vars.add(var);
763-
}
764-
765-
// Add imports
766-
for (Map<String, String> oneImport : additionalImports) {
767-
// exclude imports from this package - these are imports that only the oneOf interface needs
768-
if (!implImports.contains(oneImport) && !oneImport.getOrDefault("import", "").startsWith(modelPackage())) {
769-
implImports.add(oneImport);
770-
}
771-
}
772-
}
773743
}
774744

775-
776-
777745
@Override
778746
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
779747
objs = super.postProcessAllModels(objs);
@@ -821,7 +789,7 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
821789
if (cm.oneOf.size() > 0) {
822790
cm.vendorExtensions.put("isOneOfInterface", true);
823791
// if this is oneOf interface, make sure we include the necessary jackson imports for it
824-
for (String s : Arrays.asList("JsonTypeInfo", "JsonSubTypes")) {
792+
for (String s : Arrays.asList("JsonTypeInfo", "JsonSubTypes","JsonProperty", "ApiModelProperty")) {
825793
Map<String, String> i = new HashMap<String, String>() {{
826794
put("import", importMapping.get(s));
827795
}};
@@ -849,6 +817,8 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
849817
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
850818
CodegenProperty codegenProperty = fromProperty("property", schema);
851819
if (codegenProperty != null && codegenProperty.getComplexType() != null && schema instanceof ComposedSchema) {
820+
// will be set with imports.add(codegenParameter.baseType); in defaultcodegen
821+
imports.remove("UNKNOWN_BASE_TYPE");
852822
String codegenModelName = codegenProperty.getComplexType();
853823
codegenParameter.baseName = codegenModelName;
854824
codegenParameter.paramName = toParamName(codegenParameter.baseName);

0 commit comments

Comments
 (0)