forked from loafle/openapi-generator-original
[GO] fix: stops adding imports for nested structs (#13833)
This commit is contained in:
parent
06096d7f77
commit
fa4f7e07fe
@ -627,11 +627,39 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean addedTimeImport = false;
|
|
||||||
boolean addedOSImport = false;
|
|
||||||
for (ModelMap m : objs.getModels()) {
|
for (ModelMap m : objs.getModels()) {
|
||||||
|
boolean addedTimeImport = false;
|
||||||
|
boolean addedOSImport = false;
|
||||||
CodegenModel model = m.getModel();
|
CodegenModel model = m.getModel();
|
||||||
for (CodegenProperty cp : model.vars) {
|
|
||||||
|
List<CodegenProperty> inheritedProperties = new ArrayList<>();
|
||||||
|
if (model.getComposedSchemas() != null) {
|
||||||
|
if (model.getComposedSchemas().getAllOf() != null) {
|
||||||
|
inheritedProperties.addAll(model.getComposedSchemas().getAllOf());
|
||||||
|
}
|
||||||
|
if (model.getComposedSchemas().getAnyOf() != null) {
|
||||||
|
inheritedProperties.addAll(model.getComposedSchemas().getAnyOf());
|
||||||
|
}
|
||||||
|
if (model.getComposedSchemas().getOneOf() != null) {
|
||||||
|
inheritedProperties.addAll(model.getComposedSchemas().getOneOf());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CodegenProperty> codegenProperties = new ArrayList<>();
|
||||||
|
if(model.getIsModel() || model.getComposedSchemas() == null) {
|
||||||
|
// If the model is a model, use model.vars as it only
|
||||||
|
// contains properties the generated struct will own itself.
|
||||||
|
// If model is no model and it has no composed schemas use
|
||||||
|
// model.vars.
|
||||||
|
codegenProperties.addAll(model.vars);
|
||||||
|
} else {
|
||||||
|
// If the model is no model, but is a
|
||||||
|
// allOf, anyOf or oneOf, add all first level options
|
||||||
|
// from allOf, anyOf or oneOf.
|
||||||
|
codegenProperties.addAll(inheritedProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CodegenProperty cp : codegenProperties) {
|
||||||
if (!addedTimeImport && ("time.Time".equals(cp.dataType) ||
|
if (!addedTimeImport && ("time.Time".equals(cp.dataType) ||
|
||||||
(cp.items != null && "time.Time".equals(cp.items.dataType)))) {
|
(cp.items != null && "time.Time".equals(cp.items.dataType)))) {
|
||||||
imports.add(createMapping("import", "time"));
|
imports.add(createMapping("import", "time"));
|
||||||
@ -651,7 +679,6 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
// if oneOf contains "time.Time" type
|
// if oneOf contains "time.Time" type
|
||||||
if (!addedTimeImport && model.oneOf != null && model.oneOf.contains("time.Time")) {
|
if (!addedTimeImport && model.oneOf != null && model.oneOf.contains("time.Time")) {
|
||||||
imports.add(createMapping("import", "time"));
|
imports.add(createMapping("import", "time"));
|
||||||
addedTimeImport = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if oneOf contains "null" type
|
// if oneOf contains "null" type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user