forked from loafle/openapi-generator-original
Implement toOperationId for python-flask server codegen
and use "operationId" in the template to replace vendorExtensions.x-operationId
This commit is contained in:
@@ -207,14 +207,16 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
Path path = swagger.getPath(pathname);
|
||||
if(path.getOperations() != null) {
|
||||
for(Map.Entry<HttpMethod, Operation> entry : path.getOperationMap().entrySet()) {
|
||||
// Normalize `operationId` and add package/class path in front, e.g.
|
||||
// controllers.default_controller.add_pet
|
||||
String httpMethod = entry.getKey().name().toLowerCase();
|
||||
Operation operation = entry.getValue();
|
||||
String operationId = getOrGenerateOperationId(operation, pathname, httpMethod);
|
||||
String xOperationId = underscore(sanitizeName(operationId));
|
||||
if(!operationId.contains(".")) {
|
||||
operation.setOperationId(controllerPackage + "." + defaultController + "." + xOperationId);
|
||||
operationId = underscore(sanitizeName(operationId));
|
||||
operationId = controllerPackage + "." + defaultController + "." + operationId;
|
||||
}
|
||||
operation.setVendorExtension("x-operationId", xOperationId);
|
||||
operation.setOperationId(operationId);
|
||||
if(operation.getTags() != null) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for(String tag : operation.getTags()) {
|
||||
@@ -295,4 +297,15 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
operationId = super.toOperationId(operationId);
|
||||
// Use the part after the last dot, e.g.
|
||||
// controllers.defaultController.addPet => addPet
|
||||
operationId = operationId.replaceAll(".*\\.", "");
|
||||
// Need to underscore it since it has been processed via removeNonNameElementToCamelCase, e.g.
|
||||
// addPet => add_pet
|
||||
return underscore(operationId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user