[scala-play-server] Fix generated enums named after a reserved word #3080
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,4.1.x
,5.0.x
. Default:master
.Description of the PR
This is a bugfix for the Scala-Play language.
When an enum property's name is a reserved word in Scala, it is escaped with backticks (in
AbstractScalaCodegen
) so the generated code can compile. However, generating code with backticks is a bit tricky - the name must start and end with a backtick else the code doesn't compile.In Scala-Play language, when enum properties are generated, the enum definition is contained inside the companion object of the model. The name of the enum is camelized (as per
toEnumName
method). To be able to serialize the enums, a corresponding JSON format must be introduced as well, named<EnumName>JsonFormat
. If the enum name contains backticks (as is the case with a reserved word), the JSON format will contain backticks that are not properly terminated.For example, given the property name
type
, it is escaped to`type`
, and the enum name is camelized to`Type`
, and the resulting JSON format is named`Type`JsonFormat
which produces invalid Scala code.To fix this, I changed
toEnumName
to strip the backticks before camelizing the property's name. As of now there are no reserved words in Scala that start with an uppercase; using predefined type names (such asInt
,Array
,Any
and so on) as the enum name does not affect the compilation (i.e. these are valid names that can compile).Technical Committee
@clasnake, @jimschubert, @shijinkui, @ramzimaalej