-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a global option to customize the API name suffix #3918
Add a global option to customize the API name suffix #3918
Conversation
At a glance, how about making "Api" as the default suffix for backwards compatibility? |
*/ | ||
public String toApiName(String name) { | ||
if (name.length() == 0) { | ||
return "DefaultApi"; | ||
} | ||
return camelize(name) + "Api"; | ||
return camelize(name + "_" + apiNameSuffix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not this code is used by Java and C#, then there should be no _
before apiNameSuffix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method camelize(...) will take care of "_"
5ba2078
to
1d60826
Compare
@jfeltesse-mdsol updated README and making "Api" as the default suffix eedc039 |
Looks good to me. Thanks for the PR. The reason why we add "Api" as the default suffix is to avoid naming collisions with model name (e.g. PetApi, Pet (model)) I'll submit another PR to revise the description a little bit so as to make it clearer that the option only applies to Ruby, Python and JaxRS generator. Also I'll add the new option to maven-plugin as well as gradle-plugin |
* added apiNameSuffix parameter to control the suffixes of API class/file/doc names * added --api-name-suffix in readme
Doc update done via #4045 |
@bgong-mdsol thanks for the PR, which has been included in the v4.1.3 release: https://twitter.com/oas_generator/status/1180123829626003456 |
* master: (35 commits) [haskell-http-client] update samples (#4073) [haskell-http-client] Bump deps to LTS 14.7 (#4068) update release for 4.2.0 [typescript-axios] Fix api generating incorrect seralization type check (#4051) prepare 4.1.3 release (#4052) typescript-node: form data file (#3967) Add a link to blog post on vertx and openapi (#4048) better wording for apiNameSuffix option description (#4045) [Ruby] fix ruby test, update error message (#4041) [PHP] Correctly format JSON in headers (#4024) [haskell-http-client] add dateTimeParseFormat cli option - overrides the format string used to parse a datetime (#4037) Add frankyjuang to the C# technical committee (#4036) Feature/api name suffix (#3918) [F#] minor improvements to the generators (#3968) Repaired Checkstyle (#4029) mockito 3.1.0 (#4035) typescript-fetch: fix return type of primitive value (#4028) [typescript][node]: Add accept header if produces is not empty (#3966) [haskell-http-client] disable unused import warning in Core.hs (#4020) Add a link to the tutorial in http4k (#4019) ...
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
(details of the change, additional tests that have been done, reference to the issue for tracking, etc)
The problem:
API generation for C#, Java and Ruby creates a class based on the tag and then adds "Api" after it.
Ideally though we have a class like "Study" or "Study{{Suffix}}" not "StudyApi".
I introduced a apiNameSuffix parameter in order to add suffixes to the generated api class/file/document names. Added the option "--api-name-suffix" to allow the user specify api name suffix via openapi-generator command line, the value of apiNameSuffix is "Api" if the option "--api-name-suffix" is not provided or empty.
Sample of command line:
java -jar openapi-generator-cli.jar generate g java --api-name-suffix=client -i petstore.yaml -o out/petstore
This PR works for Java, Ruby, C# and Python
@jcarres-mdsol
@bkashyapmd
@jfeltesse-mdsol
@prajon84
@ykitamura-mdsol
@cabbott