-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Description
The Scala client codegen escapes terms which may be fairly common in response models (path, lazy, match, type). These are prefixed with an underscore with no serialization fix to account for the escaped value.
This is probably an issue in other generators as well.
Swagger-codegen version
2.2.3
Swagger declaration file content or url
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Reserved Words Issue",
"description": "A sample of reserved words being escaped and breaking serialization",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Jim Schubert"
},
"license": {
"name": "MIT"
}
},
"host": "example.com",
"basePath": "/api",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/hi": {
"get": {
"description": "Returns all examples",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "A list of examples.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Example"
}
}
}
}
}
}
},
"definitions": {
"Example": {
"type": "object",
"required": [
"id",
"name",
"path"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"path": {
"type": "string"
},
"lazy": {
"type": "boolean"
},
"match": {
"type": "integer",
"format": "int64"
},
"type": {
"type": "string"
}
}
}
}
}Command line used for generation
swagger-codegen generate -l scala -i swagger.json -o example
Steps to reproduce
- Save above spec as
swagger.json - Run above command to generate Scala client
- Inspect the model (
cat example/src/main/scala/io/swagger/client/model/Example.scala):
package io.swagger.client.model
case class Example (
id: Long,
name: String,
_path: String,
_lazy: Option[Boolean],
_match: Option[Long],
_type: Option[String]
)Related issues/PRs
Suggest a fix/enhancement
Scala allows these reserved words to be escaped in code. Model properties requiring escaping can easily be done like so:
case class Example (
id: Long,
name: String,
`path`: String,
`lazy`: Option[Boolean],
`match`: Option[Long],
`type`: Option[String]
)
Another option would be to annotate each escaped property with the unescaped property name, e.g. @JsonProperty("path"). However, this assumes only JSON serialization. This shouldn't be a huge issue, considering the ApiInvoker for the Scala generator assumes JSON serialization.
I'd imagine the escapes would be a better solution, especially for anyone who may only be generating models without API implementations.