Skip to content
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

Merged
merged 2 commits into from
Oct 3, 2019

Conversation

bgong-mdsol
Copy link
Contributor

@bgong-mdsol bgong-mdsol commented Sep 20, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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

@jfeltesse-mdsol
Copy link
Contributor

At a glance, how about making "Api" as the default suffix for backwards compatibility?
Also, you need to update the README (and other places?) to document that new option.

*/
public String toApiName(String name) {
if (name.length() == 0) {
return "DefaultApi";
}
return camelize(name) + "Api";
return camelize(name + "_" + apiNameSuffix);
Copy link
Contributor

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 ?

Copy link
Contributor Author

@bgong-mdsol bgong-mdsol Sep 20, 2019

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 "_"

@bgong-mdsol
Copy link
Contributor Author

At a glance, how about making "Api" as the default suffix for backwards compatibility?
Also, you need to update the README (and other places?) to document that new option.

@jfeltesse-mdsol updated README and making "Api" as the default suffix eedc039

@wing328
Copy link
Member

wing328 commented Oct 3, 2019

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

@wing328 wing328 added this to the 4.1.3 milestone Oct 3, 2019
@wing328 wing328 merged commit ebc9e29 into OpenAPITools:master Oct 3, 2019
Jesse0Michael pushed a commit to Jesse0Michael/openapi-generator that referenced this pull request Oct 3, 2019
* added apiNameSuffix parameter to control the suffixes of API class/file/doc names

* added --api-name-suffix in readme
@wing328 wing328 changed the title Feature/api name suffix Add a global option to customize the API name suffix Oct 3, 2019
@wing328
Copy link
Member

wing328 commented Oct 4, 2019

Doc update done via #4045

@wing328
Copy link
Member

wing328 commented Oct 4, 2019

@bgong-mdsol thanks for the PR, which has been included in the v4.1.3 release: https://twitter.com/oas_generator/status/1180123829626003456

jimschubert added a commit that referenced this pull request Oct 6, 2019
* 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)
  ...
@bgong-mdsol bgong-mdsol deleted the Feature/api_name_suffix branch June 17, 2020 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants