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

[Java][Native]Add option to use the builder pattern for API parameters #5961

Conversation

bgong-mdsol
Copy link
Contributor

@bgong-mdsol bgong-mdsol commented Apr 16, 2020

Ths PR added the option to build API requests using builder pattern for Client-Java-Native based on the request

It includes the changes below:

  • update the template of API

  • update the template of README

  • add modified template of api test under native

  • add modified template of api doc under native

  • update Petstore samples for native

  • fixed build error with null async return

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@wing328 @cbornet @jeff9finger @bbdouglas @sreeshas @jfiala @lukoyanov @karismann @Zomzog @lwlee2608 @bkabrda @jfeltesse-mdsol @jcarres-mdsol

@@ -94,7 +95,12 @@ public class {{{classname}}}Example {
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
try {
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
{{^vendorExtensions.x-group-parameters}}
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}{{#hasParams}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you break the lines like for instance

{{^vendorExtensions.x-group-parameters}}
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/vendorExtensions.x-group-parameters}}
{{#vendorExtensions.x-group-parameters}}
{{#hasParams}}
API{{operationId}}Request request = API{{operationId}}Request.newBuilder(){{#allParams}}
    .{{paramName}}({{paramName}}){{/allParams}}
    .build();
{{/hasParams}}
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{operationId}}({{#hasParams}}request{{/hasParams}});
{{/vendorExtensions.x-group-parameters}}
{{#returnType}}System.out.println(result);{{/returnType}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may add extra empty line for {{^vendorExtensions.x-group-parameters}}case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO having an extra empty line in auto generated source code is alright if it can make the maintenance easier. Also, I don't know how about the java clients but the ruby one has the option to run a linter afterwards to take care of such things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't result in empty lines if the start tag and end tag are aligned properly. Ref: https://github.com/samskivert/jmustache#newline-trimming


{{^vendorExtensions.x-group-parameters}}
> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do both {{/vend.. and {{#ven.. need to be on the same line?

@bgong-mdsol bgong-mdsol force-pushed the feature/java-native-use-builders-for-api-request branch 2 times, most recently from 95e835f to 4b4a097 Compare April 21, 2020 20:15
@bgong-mdsol bgong-mdsol force-pushed the feature/java-native-use-builders-for-api-request branch from 4b4a097 to 5e29e3f Compare June 8, 2020 17:54
Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 wing328 merged commit 71dc054 into OpenAPITools:master Jun 10, 2020
@bgong-mdsol bgong-mdsol deleted the feature/java-native-use-builders-for-api-request branch June 10, 2020 14:07
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.

[BUG] [java][asyncNative] failed to build the client generated with null async return
3 participants