Skip to content

Commit 3a09ebb

Browse files
authored
Added path param normalization for Rust clients (#20309)
1 parent 8aa8e38 commit 3a09ebb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,20 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
604604
OperationMap objectMap = objs.getOperations();
605605
List<CodegenOperation> operations = objectMap.getOperation();
606606
for (CodegenOperation operation : operations) {
607+
if (operation.pathParams != null && operation.pathParams.size() > 0) {
608+
for (var pathParam : operation.pathParams) {
609+
if (!pathParam.baseName.contains("-")) {
610+
continue;
611+
}
612+
613+
var newName = pathParam.baseName.replace("-", "_");
614+
LOGGER.info(pathParam.baseName + " cannot be used as a path param. Renamed to " + newName);
615+
616+
operation.path = operation.path.replace("{" + pathParam.baseName + "}", "{" + newName + "}");
617+
pathParam.baseName = newName;
618+
}
619+
}
620+
607621
// http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
608622
if (HYPER_LIBRARY.equals(getLibrary())) {
609623
operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));

0 commit comments

Comments
 (0)