Assist escapeReservedWord with custom mappings #4480
Merged
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.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
The escapeReservedWord method does its job fairly well, but in some cases "reserved words" make some properties look a bit odd in some languages.
The method escapeReservedWord could be assisted through an additional command line parameter (reserved-words-mappings).
In the case of Objective-C, the definition below would create a property named _id which could mistakenly be interpreted as an iVar.
which in turn yields
The escapeReservedWord method could look up what _id should be substituted with instead.
For example,
java -jar swagger-codegen-cli.jar generate -i pet.yaml -l objc --reserved-words-mappings id=identifier -o outputThe new output
GoLang can also benefit from this, for example
Instead of this
It could generate
by using
java -jar swagger-codegen-cli.jar generate -i car.yaml -l go --reserved-words-mappings Range=Ranges -o output