OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA-VERTX-WEB] Bug generating model equals method

Open
#17,505 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

When you have a Version structure with a version field the generated equals method do not working since fields are not accessed with this..

openapi-generator version

I'm using the docker image v7.0.2.

OpenAPI declaration file content or url
{
    "schemas": {
        "Version": {
            "type": "object",
            "properties": {
                "version": {"type": "string"}
            }
        }
    }
}
Generation Details
docker run \
	--rm \
	--volume "$${PWD}:/local" \
	openapitools/openapi-generator-cli:v7.2.0 \
	generate \
		--global-property models \
		--input-spec /local/openapi.json \
		--generator-name java-vertx-web \
		--output /local/backend/
Suggest a fix

Change generation to have this diff on generated output :

diff --git a/backend/.../model/Version.java b/backend/.../model/Version.java
index b3ef134..e889c27 100644
--- a/backend/.../model/Version.java
+++ b/backend/.../model/Version.java
@@ -30,11 +30,11 @@ public class Version   {
   @Override
   public boolean equals(Object o) {
     if (this == o) {
       return true;
     }
     if (o == null || getClass() != o.getClass()) {
       return false;
     }
     Version version = (Version) o;
-    return Objects.equals(version, version.version);
+    return Objects.equals(this.version, version.version);
   }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided Docker generation command and inspect the generated backend/.../model/Version.java file. Compare the equals method with the suggested diff, then trace the Java Vert.x Web model-generation entry point that produces it. Done means the generated method accesses the current object's field with this.version and the reproduction no longer fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.