swagger-api / swagger-api/swagger-codegen-generators
[Java/Spring] Child without properties does not have super.equals
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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