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

Generate hashCode and equals #1201

Merged

Conversation

miguel-vila
Copy link
Contributor

@miguel-vila miguel-vila commented Sep 19, 2024

Description

Generate hashCode and equals methods.

Issues Resolved

#312

Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

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

@miguel-vila This is really cool to see, thank you for picking this up!

Have added a few comments.

miguel-vila and others added 8 commits September 20, 2024 10:10
Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: miguel-vila <[email protected]>
@miguel-vila
Copy link
Contributor Author

@Xtansia I have addressed most of your comments, the remaining one is regarding using an import instead of the fqn for java.util.Objects. Not sure how to do that.

I'm also interested in these changes because I want to have these methods in classes like TypeMapping and IndexSettings but I see that they are not being codegenerated at the moment. What should be done for that?

@Xtansia
Copy link
Collaborator

Xtansia commented Sep 22, 2024

I'm also interested in these changes because I want to have these methods in classes like TypeMapping and IndexSettings but I see that they are not being codegenerated at the moment. What should be done for that?

@miguel-vila Yeah, we're currently doing a bit of a piecemeal approach to get things to be generated. It's somewhat slow going as when we do generate new sections there are breaking changes and other differences with the current client implementation, which requires evaluating between the client, the spec & the server what the correct expectation is.

So for some of the more complex structures it might be faster/easier to add them to your required types by hand. However if you're interested in helping out with moving even 1 or 2 requests to be generated that would be amazing.

@miguel-vila
Copy link
Contributor Author

@Xtansia I would prefer not to add those manually, but not sure what would be the changes needed to include them in the codegeneration. Locally, I modified the OPERATION_MATCHER constant in the CodeGenerator class to include and(namespace("indices"), named("get")) and I'm seeing some errors :

java.lang.UnsupportedOperationException: Can not get type name for oneOf: [org.opensearch.client.codegen.openapi.OpenApiSchema@134060ce[pointer=/components/schemas/_common.analysis:TokenFilter/oneOf/0], org.opensearch.client.codegen.openapi.OpenApiSchema@33443e63[pointer=/components/schemas/_common.analysis:TokenFilter/oneOf/1]]
        at org.opensearch.client.codegen.model.SpecTransformer.mapOneOf(SpecTransformer.java:467
...

Is it possible that these errors would require more changes than adding the methods manually?

@Xtansia
Copy link
Collaborator

Xtansia commented Sep 24, 2024

@Xtansia I would prefer not to add those manually, but not sure what would be the changes needed to include them in the codegeneration. Locally, I modified the OPERATION_MATCHER constant in the CodeGenerator class to include and(namespace("indices"), named("get")) and I'm seeing some errors :

java.lang.UnsupportedOperationException: Can not get type name for oneOf: [org.opensearch.client.codegen.openapi.OpenApiSchema@134060ce[pointer=/components/schemas/_common.analysis:TokenFilter/oneOf/0], org.opensearch.client.codegen.openapi.OpenApiSchema@33443e63[pointer=/components/schemas/_common.analysis:TokenFilter/oneOf/1]]
        at org.opensearch.client.codegen.model.SpecTransformer.mapOneOf(SpecTransformer.java:467
...

Is it possible that these errors would require more changes than adding the methods manually?

There's likely more edge cases that'll pop up with something as expansive as indices.get, but would also unblock a lot of things with getting them implemented. I'll give it an investigate and see if I can get it working.

@reta reta self-requested a review September 27, 2024 18:34
@Xtansia Xtansia merged commit 18a8460 into opensearch-project:main Sep 30, 2024
57 checks passed
@Xtansia Xtansia mentioned this pull request Sep 30, 2024
Xtansia added a commit to Xtansia/opensearch-java that referenced this pull request Oct 1, 2024
* Generate hashCode and equals , wip

Signed-off-by: miguel-vila <[email protected]>

* add changelog entry

Signed-off-by: miguel-vila <[email protected]>

* remove change

Signed-off-by: miguel-vila <[email protected]>

* take into account primitives

Signed-off-by: miguel-vila <[email protected]>

* refactor and format

Signed-off-by: miguel-vila <[email protected]>

* use Object.equals

Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>

* use `&&` chain

Signed-off-by: miguel-vila <[email protected]>

* adjust last line

Signed-off-by: miguel-vila <[email protected]>

* use fqn

Signed-off-by: miguel-vila <[email protected]>

* use fqn for Objects.hashCode, take into account parent

Signed-off-by: miguel-vila <[email protected]>

* remove unused var definition

Signed-off-by: miguel-vila <[email protected]>

* codegen equals/hashCode for request shapes

Signed-off-by: miguel-vila <[email protected]>

* add hashCode/equals to TaggedUnion

Signed-off-by: miguel-vila <[email protected]>

* use import

Signed-off-by: miguel-vila <[email protected]>

* fix equals for request shapes

Signed-off-by: miguel-vila <[email protected]>

* codegen latest from main

Signed-off-by: miguel-vila <[email protected]>

---------

Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
(cherry picked from commit 18a8460)
Xtansia added a commit to Xtansia/opensearch-java that referenced this pull request Oct 1, 2024
* Generate hashCode and equals , wip

Signed-off-by: miguel-vila <[email protected]>

* add changelog entry

Signed-off-by: miguel-vila <[email protected]>

* remove change

Signed-off-by: miguel-vila <[email protected]>

* take into account primitives

Signed-off-by: miguel-vila <[email protected]>

* refactor and format

Signed-off-by: miguel-vila <[email protected]>

* use Object.equals

Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>

* use `&&` chain

Signed-off-by: miguel-vila <[email protected]>

* adjust last line

Signed-off-by: miguel-vila <[email protected]>

* use fqn

Signed-off-by: miguel-vila <[email protected]>

* use fqn for Objects.hashCode, take into account parent

Signed-off-by: miguel-vila <[email protected]>

* remove unused var definition

Signed-off-by: miguel-vila <[email protected]>

* codegen equals/hashCode for request shapes

Signed-off-by: miguel-vila <[email protected]>

* add hashCode/equals to TaggedUnion

Signed-off-by: miguel-vila <[email protected]>

* use import

Signed-off-by: miguel-vila <[email protected]>

* fix equals for request shapes

Signed-off-by: miguel-vila <[email protected]>

* codegen latest from main

Signed-off-by: miguel-vila <[email protected]>

---------

Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 18a8460)
Xtansia added a commit that referenced this pull request Oct 1, 2024
* Generate hashCode and equals (#1201)

* Generate hashCode and equals , wip

Signed-off-by: miguel-vila <[email protected]>

* add changelog entry

Signed-off-by: miguel-vila <[email protected]>

* remove change

Signed-off-by: miguel-vila <[email protected]>

* take into account primitives

Signed-off-by: miguel-vila <[email protected]>

* refactor and format

Signed-off-by: miguel-vila <[email protected]>

* use Object.equals

Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>

* use `&&` chain

Signed-off-by: miguel-vila <[email protected]>

* adjust last line

Signed-off-by: miguel-vila <[email protected]>

* use fqn

Signed-off-by: miguel-vila <[email protected]>

* use fqn for Objects.hashCode, take into account parent

Signed-off-by: miguel-vila <[email protected]>

* remove unused var definition

Signed-off-by: miguel-vila <[email protected]>

* codegen equals/hashCode for request shapes

Signed-off-by: miguel-vila <[email protected]>

* add hashCode/equals to TaggedUnion

Signed-off-by: miguel-vila <[email protected]>

* use import

Signed-off-by: miguel-vila <[email protected]>

* fix equals for request shapes

Signed-off-by: miguel-vila <[email protected]>

* codegen latest from main

Signed-off-by: miguel-vila <[email protected]>

---------

Signed-off-by: miguel-vila <[email protected]>
Signed-off-by: Miguel Vilá <[email protected]>
Co-authored-by: Thomas Farr <[email protected]>
Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 18a8460)

* Re-run codegen (#1216)

* Re-run codegen

Signed-off-by: Thomas Farr <[email protected]>

* Improve null handling

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
(cherry picked from commit 897cc9b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants