Skip to content

feat: Add types-import missing for go code generator. #12906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -314,6 +314,15 @@ public String toModel(String name, boolean doUnderscore) {
return name;
}

@Override
public CodegenModel fromModel(String name, Schema schema) {
CodegenModel gotcm = super.fromModel(name, schema);
if(schema.getEnum() != null && !schema.getEnum().isEmpty()){
gotcm.dataType = schema.getType();
}
return gotcm;
}

@Override
public String toApiFilename(String name) {
final String apiName;
Expand Down Expand Up @@ -611,6 +620,7 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert

@Override
public ModelsMap postProcessModels(ModelsMap objs) {
List<String> addedbaseType = new ArrayList<String>();
// remove model imports to avoid error
List<Map<String, String>> imports = objs.getImports();
final String prefix = modelPackage();
Expand All @@ -619,6 +629,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
String _import = iterator.next().get("import");
if (_import.startsWith(prefix))
iterator.remove();
addedbaseType.add(_import);
}

boolean addedTimeImport = false;
Expand All @@ -635,6 +646,14 @@ public ModelsMap postProcessModels(ModelsMap objs) {
imports.add(createMapping("import", "os"));
addedOSImport = true;
}

if(!languageSpecificPrimitives.contains(param.dataType)){
String _import = param.dataType;
if (importMapping.containsKey(_import) && !addedbaseType.contains(importMapping.get(_import))) {
imports.add(createMapping("import", importMapping.get(_import)));
addedbaseType.add(importMapping.get(_import));
}
}
}

if (this instanceof GoClientCodegen && model.isEnum) {
Expand Down Expand Up @@ -663,8 +682,9 @@ public ModelsMap postProcessModels(ModelsMap objs) {
String _import = listIterator.next().get("import");
// if the import package happens to be found in the importMapping (key)
// add the corresponding import package to the list
if (importMapping.containsKey(_import)) {
if (importMapping.containsKey(_import) && !addedbaseType.contains(importMapping.get(_import)) ) {
listIterator.add(createMapping("import", importMapping.get(_import)));
addedbaseType.add(importMapping.get(_import));
}
}

Expand Down