swagger-api / swagger-api/swagger-codegen-generators

[Java/Spring] Child without properties does not have super.equals

Open Beginner friendly
#860 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

The following definitions:

  ObjectA:
    type: object
    properties:
      a:
        type: string
    required:
      - a
  ObjectB:
    allOf:
      - $ref: '#/[...]/ObjectA'
      - type: object
        required: 
        - b
        properties:
          b:
            type: string

generates a class for ObjectB which contains

  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    ObjectB objectB= (ObjectB) o;
    return Objects.equals(this.b, objectB.b) &&
        super.equals(o);
  }

However, these definitions:

  ObjectA:
    type: object
    properties:
      a:
        type: string
    required:
      - a
  ObjectB:
    allOf:
      - $ref: '#/[...]/ObjectA'
      - type: object

generates a class for ObjectB which contains

  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    return true;
  }

This however, is falsy.
It also shows in https://github.com/swagger-api/swagger-codegen-generators/blob/dddb3f3ab95b9859927c1b54215651046676e475/src/main/resources/handlebars/Java/pojo.mustache#L181 that this was an issue for plain java before.
Therefore https://github.com/swagger-api/swagger-codegen-generators/blob/dddb3f3ab95b9859927c1b54215651046676e475/src/main/resources/handlebars/JavaSpring/pojo.mustache#L124 should be changed accordingly.

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

Start in src/main/resources/handlebars/JavaSpring/pojo.mustache around line 124, then compare the corresponding equals implementation in src/main/resources/handlebars/Java/pojo.mustache around line 181. Verify the generated ObjectB equals method preserves superclass equality even when the child has no properties; done means the JavaSpring template handles both child shapes consistently.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.