Skip to content

Commit 447bb46

Browse files
committed
Suggestion: Generate equals and hashcode in models.
1 parent 4d7108d commit 447bb46

File tree

1 file changed

+44
-0
lines changed
  • client/deployment/src/main/resources/templates/libraries/microprofile

1 file changed

+44
-0
lines changed

client/deployment/src/main/resources/templates/libraries/microprofile/pojo.qute

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{@org.openapitools.codegen.CodegenModel m}
22
import com.fasterxml.jackson.annotation.JsonProperty;
3+
import java.util.Objects;
34

45
{#if m.description}
56
/**
@@ -135,6 +136,49 @@ public class {m.classname} {#if m.parent}extends {m.parent}{/if}{#if serializabl
135136
return sb.toString();
136137
}
137138

139+
{#if m.vars.size > 0}
140+
@Override
141+
public boolean equals(Object o) {
142+
if (this == o) return true;
143+
if (o == null || getClass() != o.getClass()) return false;
144+
145+
{m.classname} model = ({m.classname}) o;
146+
147+
{#if m.vars.size == 1}
148+
return Objects.equals({m.vars.0.name}, model.{m.vars.0.name});
149+
{#else}
150+
{#for v in m.vars}
151+
{#if v_isFirst}
152+
return Objects.equals({v.name}, model.{v.name}) &&
153+
{#else if v_isLast}
154+
Objects.equals({v.name}, model.{v.name});
155+
{#else}
156+
Objects.equals({v.name}, model.{v.name}) &&
157+
{/if}
158+
{/for}
159+
{/if}
160+
}
161+
{/if}
162+
163+
{#if m.vars.size > 0}
164+
@Override
165+
public int hashCode() {
166+
{#if m.vars.size == 1}
167+
return Objects.hash({m.vars.0.name});
168+
{#else}
169+
{#for v in m.vars}
170+
{#if v_isFirst}
171+
return Objects.hash({v.name},
172+
{#else if v_isLast}
173+
{v.name});
174+
{#else}
175+
{v.name},
176+
{/if}
177+
{/for}
178+
{/if}
179+
}
180+
{/if}
181+
138182
/**
139183
* Convert the given object to string with each line indented by 4 spaces
140184
* (except the first line).

0 commit comments

Comments
 (0)