Skip to content
Merged
Show file tree
Hide file tree
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 @@ -5657,6 +5657,7 @@ protected boolean isReservedWord(String word) {
*/
protected String getOrGenerateOperationId(Operation operation, String path, String httpMethod) {
String operationId = operation.getOperationId();

if (StringUtils.isBlank(operationId)) {
String tmpPath = path;
tmpPath = tmpPath.replaceAll("\\{", "");
Expand All @@ -5681,6 +5682,10 @@ protected String getOrGenerateOperationId(Operation operation, String path, Stri
LOGGER.warn("Empty operationId found for path: {} {}. Renamed to auto-generated operationId: {}", httpMethod, path, operationId);
}

if (operationIdNameMapping.containsKey(operationId)) {
return operationIdNameMapping.get(operationId);
}

// remove prefix in operationId
if (removeOperationIdPrefix) {
// The prefix is everything before the removeOperationIdPrefixCount occurrence of removeOperationIdPrefixDelimiter
Expand All @@ -5693,13 +5698,8 @@ protected String getOrGenerateOperationId(Operation operation, String path, Stri
operationId = String.join(removeOperationIdPrefixDelimiter, Arrays.copyOfRange(components, component_number, components.length));
}
}
operationId = removeNonNameElementToCamelCase(operationId);

if (operationIdNameMapping.containsKey(operationId)) {
return operationIdNameMapping.get(operationId);
} else {
return toOperationId(operationId);
}
return toOperationId(removeNonNameElementToCamelCase(operationId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,20 @@ public void schemaMapping() {
Assertions.assertEquals(codegenModel.vars.get(0).getBaseType(), "TypeAlias");
}

@Test
public void operationIdNameMapping() {
DefaultCodegen codegen = new DefaultCodegen();
codegen.operationIdNameMapping.put("edge case !@# 123", "fix_edge_case");

OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/3_0/type-alias.yaml", null, new ParseOptions()).getOpenAPI();
codegen.setOpenAPI(openAPI);

CodegenOperation codegenOperation = codegen.fromOperation("/type-alias", "get", openAPI.getPaths().get("/type-alias").getGet(), null);
Assertions.assertEquals(codegenOperation.operationId, "fix_edge_case");
Assertions.assertEquals(codegen.getOrGenerateOperationId(openAPI.getPaths().get("/type-alias").getGet(), "/type-alias", "get"), "fix_edge_case");
}

@Test
public void modelWithPrefixDoNotContainInheritedVars() {
DefaultCodegen codegen = new DefaultCodegen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ info:
paths:
/type-alias:
get:
operationId: edge case !@# 123
responses:
200:
description: OK
Expand Down
Loading