Added path param normalization for Rust clients (#20309)

This commit is contained in:
Ross 2024-12-14 14:37:15 +09:00 committed by GitHub
parent 8aa8e3892d
commit 3a09ebbb7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -604,6 +604,20 @@ public class RustClientCodegen extends AbstractRustCodegen implements CodegenCon
OperationMap objectMap = objs.getOperations();
List<CodegenOperation> operations = objectMap.getOperation();
for (CodegenOperation operation : operations) {
if (operation.pathParams != null && operation.pathParams.size() > 0) {
for (var pathParam : operation.pathParams) {
if (!pathParam.baseName.contains("-")) {
continue;
}
var newName = pathParam.baseName.replace("-", "_");
LOGGER.info(pathParam.baseName + " cannot be used as a path param. Renamed to " + newName);
operation.path = operation.path.replace("{" + pathParam.baseName + "}", "{" + newName + "}");
pathParam.baseName = newName;
}
}
// http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
if (HYPER_LIBRARY.equals(getLibrary())) {
operation.httpMethod = StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT));