Skip to content

Commit

Permalink
Merge pull request #1 from SpectraLogic/lumos/revertNullabilityChange
Browse files Browse the repository at this point in the history
Lumos/revert nullability change
  • Loading branch information
icubbon authored Mar 28, 2024
2 parents e78aeb6 + 384be07 commit 44e2838
Show file tree
Hide file tree
Showing 39 changed files with 800 additions and 1,507 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ nb-configuration.xml
*.pm~
*.xml~
*.t~
?/.m2/
?/.config/jgit/config

/target
/generated-files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import java.io.File;
import java.util.*;

import static org.openapitools.codegen.utils.StringUtils.camelize;

public class GoServerCodegen extends AbstractGoCodegen {

/**
Expand Down Expand Up @@ -324,77 +322,34 @@ public ModelsMap postProcessModels(ModelsMap objs) {

@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
// TODO: refactor abstractGoCodegen, decouple go client only code and remove this
objs = super.postProcessOperationsWithModels(objs, allModels);
OperationMap objectMap = objs.getOperations();
List<CodegenOperation> operations = objectMap.getOperation();

for (CodegenOperation operation : operations) {
// http method verb conversion (e.g. PUT => Put)
operation.httpMethod = camelize(operation.httpMethod.toLowerCase(Locale.ROOT));
}

// remove model imports to avoid error
List<Map<String, String>> imports = objs.getImports();
if (imports == null)
return objs;

Iterator<Map<String, String>> iterator = imports.iterator();
while (iterator.hasNext()) {
String _import = iterator.next().get("import");
if (_import.startsWith(apiPackage))
iterator.remove();
}
// override imports to only include packages for interface parameters
imports.clear();

boolean addedTimeImport = false;
boolean addedOSImport = false;
boolean addedReflectImport = false;
for (CodegenOperation operation : operations) {
for (CodegenParameter param : operation.allParams) {
// import "os" if the operation uses files
if (!addedOSImport && ("*os.File".equals(param.dataType) || "[]*os.File".equals(param.dataType))) {
if (!addedOSImport && ("*os.File".equals(param.dataType) || ("[]*os.File".equals(param.dataType)))) {
imports.add(createMapping("import", "os"));
addedOSImport = true;
}

// import "time" if the operation has a time parameter.
if (!addedTimeImport && "time.Time".equals(param.dataType)) {
imports.add(createMapping("import", "time"));
addedTimeImport = true;
}

// import "reflect" package if the parameter is collectionFormat=multi
if (!addedReflectImport && param.isCollectionFormatMulti) {
imports.add(createMapping("import", "reflect"));
addedReflectImport = true;
// import "time" if the operation has a required time parameter
if (param.required) {
if (!addedTimeImport && "time.Time".equals(param.dataType)) {
imports.add(createMapping("import", "time"));
addedTimeImport = true;
}
}

// set x-exportParamName
char nameFirstChar = param.paramName.charAt(0);
if (Character.isUpperCase(nameFirstChar)) {
// First char is already uppercase, just use paramName.
param.vendorExtensions.put("x-export-param-name", param.paramName);
} else {
// It's a lowercase first char, let's convert it to uppercase
StringBuilder sb = new StringBuilder(param.paramName);
sb.setCharAt(0, Character.toUpperCase(nameFirstChar));
param.vendorExtensions.put("x-export-param-name", sb.toString());
}
}

}

// recursively add import for mapping one type to multiple imports
List<Map<String, String>> recursiveImports = objs.getImports();
if (recursiveImports == null)
return objs;

ListIterator<Map<String, String>> listIterator = imports.listIterator();
while (listIterator.hasNext()) {
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)) {
listIterator.add(createMapping("import", importMapping.get(_import)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ type {{classname}}Servicer interface { {{#operations}}{{#operation}}
{{#isDeprecated}}
// Deprecated
{{/isDeprecated}}
{{operationId}}(context.Context{{#allParams}}, {{#isNullable}}*{{/isNullable}}{{dataType}}{{/allParams}}) (ImplResponse, error){{/operation}}{{/operations}}
{{operationId}}(context.Context{{#allParams}}, {{^required}}{{^isArray}}{{^isFile}}*{{/isFile}}{{/isArray}}{{/required}}{{dataType}}{{/allParams}}) (ImplResponse, error){{/operation}}{{/operations}}
}{{/apis}}{{/apiInfo}}
Loading

0 comments on commit 44e2838

Please sign in to comment.