-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
Milestone
Description
Description
The scala client code generator supports using UUID types of the form {"type": "string", "format": "uuid"}. This correctly generates models that use java.util.UUID. However when you use this API you get errors like the following:
[error] /src/main/scala/io/swagger/client/api/RoutesApi.scala:605: overloaded method value escape with alternatives:
[error] (value: Float)String <and>
[error] (value: Double)String <and>
[error] (value: Long)String <and>
[error] (value: String)String
[error] cannot be applied to (java.util.UUID)
[error] val path = "/api/thing/{id}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", apiInvoker.escape(id))
[error] ^
In the generated ApiInvoker.scala we have:
def escape(value: String): String = {
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
}
def escape(value: Long): String = value.toString
def escape(value: Double): String = value.toString
def escape(value: Float): String = value.toString
All we need to add is the corresponding def escape(value: UUID): String = value.toString.
Swagger-codegen version
2.2.1
Swagger declaration file content or url
Any definition with type "string" and format "uuid" should generate this.
{"type": "string", "format": "uuid"}
Command line used for generation
import io.swagger.codegen.DefaultGenerator
import io.swagger.codegen.languages.ScalaClientCodegen
import io.swagger.codegen.{ClientOptInput, ClientOpts}
import io.swagger.parser.SwaggerParser;
val swagger = new SwaggerParser().read("swagger.json")
val config = new ScalaClientCodegen()
config.setOutputDir("generated_code")
val input = new ClientOptInput()
.opts(new ClientOpts())
.swagger(swagger)
.config(config)
new DefaultGenerator().opts(input).generate()
Steps to reproduce
Generate a Scala language client with a schema that has a definition with UUID format type.
Related issues
n/a
Suggest a Fix
Add def escape(value: UUID): String = value.toString to the right spot in the ApiInvoker.scala generation. Also need to import java.util.UUID in the same file.