Skip to content

[Java] add nullable annotation to pojo template for non-required fields #3409

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

Merged
merged 7 commits into from
Jul 25, 2019
Merged

[Java] add nullable annotation to pojo template for non-required fields #3409

merged 7 commits into from
Jul 25, 2019

Conversation

kassim
Copy link
Contributor

@kassim kassim commented Jul 21, 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.

@bbdouglas
@sreeshas
@jfiala
@lukoyanov
@cbornet
@jeff9finger
@karismann
@Zomzog

Description of the PR

fixes #3264

adds @javax.annotation.Nullable to non-required fields, to enhance IDE feedback and Kotlin-interop

this requires the com.google.code.findbugs:jsr305:3.0.2 dependency for the annotation - I'm not sure where I should adjust the sample dependencies (I adjusted the pom.xml / build.gradle in the sample but the integration test still fails) documentation to inform people this

existing tests are working fine, I don't think additional ones are necessary

@@ -129,6 +129,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
{{/maximum}}
* @return {{name}}
**/
{{^required}} @javax.annotation.Nullable {{/required}}
Copy link
Member

Choose a reason for hiding this comment

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

@kassim thanks for the PR. Can you use the following instead to avoid blank lines or trailing spaces?

  {{^required}}
  @javax.annotation.Nullable
  {{/required}}

Copy link
Member

Choose a reason for hiding this comment

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

I'll do it in another PR.

Copy link
Member

Choose a reason for hiding this comment

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

Filed #3453

@wing328 wing328 merged commit ee538be into OpenAPITools:master Jul 25, 2019
@wing328 wing328 added this to the 4.1.0 milestone Jul 25, 2019
@kassim kassim deleted the java-nullable branch July 25, 2019 10:26
@wing328
Copy link
Member

wing328 commented Aug 10, 2019

@kassim thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553

@kassim
Copy link
Contributor Author

kassim commented Aug 10, 2019

cheers 🍺 glad to have contributed to the project

@szczebel
Copy link

Is there a way to switch this off when using openapi-generator-maven-plugin?
In case I don't want jsr305 on classpath, I would like to have an option such as:

<configOptions>
  <generate.javax.annotation.Nullable>false</generate.javax.annotation.Nullable>
</configOptions>

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.

[REQ] [Java] add @Nullable annotation to generated model fields that aren't "required"
3 participants