[BUG] [scala-sttp] Compilation fails with non-camelCase URI parameters
Created by: softdevca
The scala-sttp generator fails to compile when URI parameters are not camelCase. This is because method parameters in the API classes are converted to camelCase but the parameter names in the URI string are not converted.
For example, in the body below the compiler cannot find the address_id
variable in the URI string because the parameter has been named addressId
.
def getAddress(addressId: String): Request[Either[ResponseError[Exception], AddressResponse], Nothing] =
basicRequest
.method(Method.GET, uri"$baseUrl/addresses/${address_id}")
.contentType("application/json")
.response(asJson[AddressResponse])
This is not an issue with the scala-akka generator because it's URI parameters are added by a method parameter.
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
master, not a regression
Steps to reproduce
The below test should verify the correct behavior.
package org.openapitools.codegen.scala;
import org.openapitools.codegen.languages.ScalaSttpClientCodegen;
import org.testng.Assert;
import org.testng.annotations.Test;
public class SttpCodegenTest {
private final ScalaSttpClientCodegen codegen = new ScalaSttpClientCodegen();
@Test
public void encodePath() {
Assert.assertEquals(codegen.encodePath("{user_name}"), "${userName}");
Assert.assertEquals(codegen.encodePath("{userName}"), "${userName");
Assert.assertEquals(codegen.encodePath("{UserName}"), "${userName}");
Assert.assertEquals(codegen.encodePath("user_name"), "user_name");
Assert.assertEquals(codegen.encodePath("before/{UserName}/after"), "before/${userName}/after");
}
}
Suggest a fix
Update ScalaSttpClientCodegen.encodePath
to do name substitution. I will do this and submit a pull request.