Skip to content

Instantly share code, notes, and snippets.

@gcatanese
Created June 10, 2022 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcatanese/6b84046488c4d62ac0eb4110a9cb52e8 to your computer and use it in GitHub Desktop.
Save gcatanese/6b84046488c4d62ac0eb4110a9cb52e8 to your computer and use it in GitHub Desktop.
Custom OpenApi Go Client Code Generator
package org.mycompany.codegen;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class MyGoClientCodegen extends GoClientCodegen {
private final Logger LOGGER = LoggerFactory.getLogger(MyGoClientCodegen.class);
@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
OperationsMap operationsMap = super.postProcessOperationsWithModels(objs, allModels);
OperationMap operations = objs.getOperations();
List<CodegenOperation> operationList = operations.getOperation();
for (CodegenOperation op : operationList) {
LOGGER.info(op.operationId);
// renaming operationId (remove verb prefix)
op.operationId = op.operationId.replace("Post", "");
op.operationId = op.operationId.replace("Get", "");
op.operationId = op.operationId.replace("Patch", "");
op.operationId = op.operationId.replace("Put", "");
op.operationId = op.operationId.substring(0, 1).toLowerCase() + op.operationId.substring(1);
}
return operationsMap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment