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 equals and hashCode methods to Microprofile #20011

Merged
merged 4 commits into from
Nov 10, 2024

Conversation

DielN
Copy link
Contributor

@DielN DielN commented Nov 1, 2024

Closes #19910

Added equals and hashCode methods to the Java Microprofile generator. The methods were copied over from the Java generator. As I suggested in the issue, I added a new template for this so it is easier to customize these if needed. I decided to also put the toString method in there to allow for easy customization as well. So all of the pojo's Object method overrides are now in that template.

This is a draft for now as I still need to do testing.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@DielN DielN marked this pull request as ready for review November 2, 2024 16:26
@DielN
Copy link
Contributor Author

DielN commented Nov 2, 2024

This is ready for review now.
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)

@wing328
Copy link
Member

wing328 commented Nov 6, 2024

--- a/bin/configs/java-microprofile-rest-client-3.0-jackson.yaml
+++ b/bin/configs/java-microprofile-rest-client-3.0-jackson.yaml
@@ -9,3 +9,4 @@ additionalProperties:
   configKey: petstore
   microprofileRestClientVersion: "3.0"
   hideGenerationTimestamp: true
+  useReflectionEqualsHashCode: true

I did a test with the above change, updated the samples but then I got errors when running mvn integration-test -f samples/client/petstore/java/microprofile-rest-client-3.0-jackson/pom.xml

ect microprofile-rest-client-3-jackson: Compilation failure: Compilation failure:
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/User.java:[15,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/User.java:[16,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Category.java:[15,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Category.java:[16,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Tag.java:[15,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Tag.java:[16,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Pet.java:[15,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Pet.java:[16,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/ModelApiResponse.java:[15,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/ModelApiResponse.java:[16,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Order.java:[15,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Order.java:[16,40] package org.apache.commons.lang3.builder does not exist
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/User.java:[272,12] cannot find symbol
[ERROR]   symbol:   variable EqualsBuilder
[ERROR]   location: class org.openapitools.client.model.User
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/User.java:[277,12] cannot find symbol
[ERROR]   symbol:   variable HashCodeBuilder
[ERROR]   location: class org.openapitools.client.model.User
[ERROR] /C:/Users/wing3/Code/openapi-generator/samples/client/petstore/java/microprofile-rest-client-3.0-jackson/src/main/java/org/openapitools/client/model/Category.java:[95,12] cannot find symbol
[ERROR]   symbol:   variable EqualsBuilder
[ERROR]   location: class org.openapitools.client.model.Category

Does it work for you locally?

@wing328
Copy link
Member

wing328 commented Nov 6, 2024

please also update bin/configs/java-microprofile-rest-client-3.0-jackson.yaml with useReflectionEqualsHashCode: true so that we have useReflectionEqualsHashCode covered moving forward.

@DielN
Copy link
Contributor Author

DielN commented Nov 9, 2024

Good catch, I missed that. The commons-lang3 dependency was missing in the pom.

There are actually quite a lot of libraries (all except okhttp in fact) where that dependency is missing. I suppose I'll create an issue for that.

The 3.0 pom is also missing the mutiny dependency, but I suggest just fixing that with the other issues in another PR

@wing328
Copy link
Member

wing328 commented Nov 10, 2024

There are actually quite a lot of libraries (all except okhttp in fact) where that dependency is missing. I suppose I'll create an issue for that.

The 3.0 pom is also missing the mutiny dependency, but I suggest just fixing that with the other issues in another PR

yes please 🙏

@wing328 wing328 merged commit 2a17134 into OpenAPITools:master Nov 10, 2024
85 checks passed
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][Microprofile] Add equals() & hashCode()
3 participants