Assist escapeReservedWord with custom mappings#4480
Merged
wing328 merged 4 commits intoswagger-api:masterfrom Jan 9, 2017
AlexNolasco:issue-4416
Merged
Assist escapeReservedWord with custom mappings#4480wing328 merged 4 commits intoswagger-api:masterfrom AlexNolasco:issue-4416
wing328 merged 4 commits intoswagger-api:masterfrom
AlexNolasco:issue-4416
Conversation
# Conflicts: # modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java
Contributor
|
@AlexanderN thanks for the enhancement. I'm sure other Swagger Codegen users will find this new feature useful in customizing the output. |
davidgri
pushed a commit
to davidgri/swagger-codegen
that referenced
this pull request
May 11, 2017
…api#4480) * Preliminary implementation for issue-4416 * Updated README.md with reserved-words-mappings parameter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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