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] option for the prefix of boolean getters #432

Merged
merged 8 commits into from
Jul 3, 2018

Conversation

jmini
Copy link
Member

@jmini jmini commented Jul 1, 2018

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 and ./bin/security/{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\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
    Java: @bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01)

Description of the PR

This PR adds a new option to all java generators (java client, jaxrs server, spring, …): booleanGetterPrefix

This new option influence the name of the getter generated for a boolean property in a model.

Example values for booleanGetterPrefix:

  • is: default value in 3.0.x.
  • get: new default value starting with 3.1.0

With following OAS3 (extract):

components:
  schemas:
  schemas:
    Order:
      type: object
      properties:
        id:
          type: integer
          format: int64
        status:
          type: string
          enum:
            - placed
            - approved
            - delivered
        complete:
          type: boolean

Generated code with is value:

  public Boolean isComplete() {
    return complete;
  }

With get value:

  public Boolean getComplete() {
    return complete;
  }

This was also discussed in:

@cbornet
Copy link
Member

cbornet commented Jul 1, 2018

If this PR is for 3.1.0, I suggest making the change to get as default now

@jmini
Copy link
Member Author

jmini commented Jul 1, 2018

@cbornet: yes current change is as minimal as possible (no impact on the generated code).
Modifying the default value can be made in a follow up PR.

@jmini
Copy link
Member Author

jmini commented Jul 2, 2018

I have pushed some more commits to change the default value.

I also think that it is important for our users to have a short list of the breaking changes in a major/minor release.

I have started docs/migration-guide.adoc to list all breaking changes of a release.

* Links to labels
* Link to PR
@jmini
Copy link
Member Author

jmini commented Jul 3, 2018

@macjohnny and @cbornet (you were both interested by the feature in a previous conversation), any additional feedback on this?

I would like to merge this, but until now nobody gave it a try.

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.

Did a test locally and work as expected.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

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

looks good, although I haven't tested it

@jmini jmini merged commit 7a7e221 into OpenAPITools:master Jul 3, 2018
@jmini
Copy link
Member Author

jmini commented Jul 17, 2018

Input @cbornet:

We need the getXXX() getter because of the Java Beans spec : http://www.oracle.com/technetwork/articles/javaee/spec-136004.html
isXXX() is for boolean, not for Boolean

@cbornet
Copy link
Member

cbornet commented Jul 17, 2018

At paragraph 8.3 😄

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* Add "booleanGetterPrefix" option
* Create `docs/migration-guide.adoc`
@alex-spicer
Copy link

Does this apply to other languages too? Or is this just java? jaxrs-jersey I still see isX getter.
Any forced flag to help here?

@wing328
Copy link
Member

wing328 commented Aug 31, 2021

The enhancement is made to the abstract java codegen class, which should cover all java generators.

Maybe the mustache template needs to be updated. Welcome PR to plot the enhancement form Java client mustache/generator to JAX-RS templates/generators.

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.

None yet

5 participants