Skip to content

Commit f88e043

Browse files
Replace the lombok EqualsAndHashcode with a mustache implementation
1 parent 4fc04b3 commit f88e043

5 files changed

Lines changed: 263 additions & 15 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/restclient/api.mustache

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class {{classname}} {
6060
public record {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request({{#allParams}}{{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.AbstractResource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.AbstractResource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{{dataType}}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){}
6161
{{/staticRequest}}
6262
{{#staticRequest}}
63-
@lombok.EqualsAndHashCode
6463
public static class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request {
6564
{{#allParams}}
6665
private final {{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.AbstractResource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.AbstractResource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{{dataType}}}{{/isFile}} {{paramName}};
@@ -84,6 +83,40 @@ public class {{classname}} {
8483
}
8584

8685
{{/allParams}}
86+
@Override
87+
public boolean equals(Object o) {
88+
{{#useReflectionEqualsHashCode}}
89+
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
90+
{{/useReflectionEqualsHashCode}}
91+
{{^useReflectionEqualsHashCode}}
92+
if (this == o) {
93+
return true;
94+
}
95+
if (o == null || getClass() != o.getClass()) {
96+
return false;
97+
}{{#hasVars}}
98+
{{classname}} {{classVarName}} = ({{classname}}) o;
99+
return {{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}equalsNullable(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}} &&
100+
{{/-last}}{{/vars}}{{#additionalPropertiesType}} &&
101+
Objects.equals(this.additionalProperties, {{classVarName}}.additionalProperties){{/additionalPropertiesType}}{{#parent}} &&
102+
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
103+
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
104+
{{/useReflectionEqualsHashCode}}
105+
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
106+
107+
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
108+
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
109+
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
110+
111+
@Override
112+
public int hashCode() {
113+
{{#useReflectionEqualsHashCode}}
114+
return HashCodeBuilder.reflectionHashCode(this);
115+
{{/useReflectionEqualsHashCode}}
116+
{{^useReflectionEqualsHashCode}}
117+
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}, additionalProperties{{/additionalPropertiesType}});
118+
{{/useReflectionEqualsHashCode}}
119+
}
87120
}
88121
{{/staticRequest}}
89122

modules/openapi-generator/src/main/resources/Java/libraries/webclient/api.mustache

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class {{classname}} {
5454
}
5555

5656
{{#operation}}{{#singleRequestParameter}}{{#hasParams}}{{^hasSingleParam}}
57-
@lombok.EqualsAndHashCode
5857
public {{#staticRequest}}static {{/staticRequest}}class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request {
5958
{{#allParams}}
6059
private final {{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.AbstractResource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.AbstractResource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{{dataType}}}{{/isFile}} {{paramName}};
@@ -78,6 +77,40 @@ public class {{classname}} {
7877
}
7978

8079
{{/allParams}}
80+
@Override
81+
public boolean equals(Object o) {
82+
{{#useReflectionEqualsHashCode}}
83+
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
84+
{{/useReflectionEqualsHashCode}}
85+
{{^useReflectionEqualsHashCode}}
86+
if (this == o) {
87+
return true;
88+
}
89+
if (o == null || getClass() != o.getClass()) {
90+
return false;
91+
}{{#hasVars}}
92+
{{classname}} {{classVarName}} = ({{classname}}) o;
93+
return {{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}equalsNullable(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}} &&
94+
{{/-last}}{{/vars}}{{#additionalPropertiesType}} &&
95+
Objects.equals(this.additionalProperties, {{classVarName}}.additionalProperties){{/additionalPropertiesType}}{{#parent}} &&
96+
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
97+
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
98+
{{/useReflectionEqualsHashCode}}
99+
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
100+
101+
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
102+
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
103+
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
104+
105+
@Override
106+
public int hashCode() {
107+
{{#useReflectionEqualsHashCode}}
108+
return HashCodeBuilder.reflectionHashCode(this);
109+
{{/useReflectionEqualsHashCode}}
110+
{{^useReflectionEqualsHashCode}}
111+
return Objects.hash({{#vars}}{{#vendorExtensions.x-is-jackson-optional-nullable}}hashCodeNullable({{name}}){{/vendorExtensions.x-is-jackson-optional-nullable}}{{^vendorExtensions.x-is-jackson-optional-nullable}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{/vendorExtensions.x-is-jackson-optional-nullable}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}}{{#additionalPropertiesType}}, additionalProperties{{/additionalPropertiesType}});
112+
{{/useReflectionEqualsHashCode}}
113+
}
81114
}
82115

83116
/**

samples/client/petstore/java/webclient-useSingleRequestParameter/src/main/java/org/openapitools/client/api/FakeApi.java

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ public ResponseSpec fakeHealthGetWithResponseSpec() throws WebClientResponseExce
191191
return fakeHealthGetRequestCreation();
192192
}
193193

194-
@lombok.EqualsAndHashCode
195194
public class FakeHttpSignatureTestRequest {
196195
private final Pet pet;
197196
private final String query1;
@@ -229,6 +228,21 @@ public FakeHttpSignatureTestRequest header1(String header1) {
229228
return this;
230229
}
231230

231+
@Override
232+
public boolean equals(Object o) {
233+
if (this == o) {
234+
return true;
235+
}
236+
if (o == null || getClass() != o.getClass()) {
237+
return false;
238+
}
239+
return true;
240+
}
241+
242+
@Override
243+
public int hashCode() {
244+
return Objects.hash();
245+
}
232246
}
233247

234248
/**
@@ -918,7 +932,6 @@ public ResponseSpec testBodyWithFileSchemaWithResponseSpec(FileSchemaTestClass f
918932
return testBodyWithFileSchemaRequestCreation(fileSchemaTestClass);
919933
}
920934

921-
@lombok.EqualsAndHashCode
922935
public class TestBodyWithQueryParamsRequest {
923936
private final String query;
924937
private final User user;
@@ -946,6 +959,21 @@ public TestBodyWithQueryParamsRequest user(User user) {
946959
return this;
947960
}
948961

962+
@Override
963+
public boolean equals(Object o) {
964+
if (this == o) {
965+
return true;
966+
}
967+
if (o == null || getClass() != o.getClass()) {
968+
return false;
969+
}
970+
return true;
971+
}
972+
973+
@Override
974+
public int hashCode() {
975+
return Objects.hash();
976+
}
949977
}
950978

951979
/**
@@ -1138,7 +1166,6 @@ public ResponseSpec testClientModelWithResponseSpec(Client client) throws WebCli
11381166
return testClientModelRequestCreation(client);
11391167
}
11401168

1141-
@lombok.EqualsAndHashCode
11421169
public class TestEndpointParametersRequest {
11431170
private final BigDecimal number;
11441171
private final Double _double;
@@ -1286,6 +1313,21 @@ public TestEndpointParametersRequest paramCallback(String paramCallback) {
12861313
return this;
12871314
}
12881315

1316+
@Override
1317+
public boolean equals(Object o) {
1318+
if (this == o) {
1319+
return true;
1320+
}
1321+
if (o == null || getClass() != o.getClass()) {
1322+
return false;
1323+
}
1324+
return true;
1325+
}
1326+
1327+
@Override
1328+
public int hashCode() {
1329+
return Objects.hash();
1330+
}
12891331
}
12901332

12911333
/**
@@ -1493,7 +1535,6 @@ public ResponseSpec testEndpointParametersWithResponseSpec(BigDecimal number, Do
14931535
return testEndpointParametersRequestCreation(number, _double, patternWithoutDelimiter, _byte, integer, int32, int64, _float, string, binary, date, dateTime, password, paramCallback);
14941536
}
14951537

1496-
@lombok.EqualsAndHashCode
14971538
public class TestEnumParametersRequest {
14981539
private final List<String> enumHeaderStringArray;
14991540
private final String enumHeaderString;
@@ -1591,6 +1632,21 @@ public TestEnumParametersRequest enumFormString(String enumFormString) {
15911632
return this;
15921633
}
15931634

1635+
@Override
1636+
public boolean equals(Object o) {
1637+
if (this == o) {
1638+
return true;
1639+
}
1640+
if (o == null || getClass() != o.getClass()) {
1641+
return false;
1642+
}
1643+
return true;
1644+
}
1645+
1646+
@Override
1647+
public int hashCode() {
1648+
return Objects.hash();
1649+
}
15941650
}
15951651

15961652
/**
@@ -1749,7 +1805,6 @@ public ResponseSpec testEnumParametersWithResponseSpec(List<String> enumHeaderSt
17491805
return testEnumParametersRequestCreation(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString);
17501806
}
17511807

1752-
@lombok.EqualsAndHashCode
17531808
public class TestGroupParametersRequest {
17541809
private final Integer requiredStringGroup;
17551810
private final Boolean requiredBooleanGroup;
@@ -1817,6 +1872,21 @@ public TestGroupParametersRequest int64Group(Long int64Group) {
18171872
return this;
18181873
}
18191874

1875+
@Override
1876+
public boolean equals(Object o) {
1877+
if (this == o) {
1878+
return true;
1879+
}
1880+
if (o == null || getClass() != o.getClass()) {
1881+
return false;
1882+
}
1883+
return true;
1884+
}
1885+
1886+
@Override
1887+
public int hashCode() {
1888+
return Objects.hash();
1889+
}
18201890
}
18211891

18221892
/**
@@ -2100,7 +2170,6 @@ public ResponseSpec testInlineFreeformAdditionalPropertiesWithResponseSpec(TestI
21002170
return testInlineFreeformAdditionalPropertiesRequestCreation(testInlineFreeformAdditionalPropertiesRequest);
21012171
}
21022172

2103-
@lombok.EqualsAndHashCode
21042173
public class TestJsonFormDataRequest {
21052174
private final String param;
21062175
private final String param2;
@@ -2128,6 +2197,21 @@ public TestJsonFormDataRequest param2(String param2) {
21282197
return this;
21292198
}
21302199

2200+
@Override
2201+
public boolean equals(Object o) {
2202+
if (this == o) {
2203+
return true;
2204+
}
2205+
if (o == null || getClass() != o.getClass()) {
2206+
return false;
2207+
}
2208+
return true;
2209+
}
2210+
2211+
@Override
2212+
public int hashCode() {
2213+
return Objects.hash();
2214+
}
21312215
}
21322216

21332217
/**
@@ -2318,7 +2402,6 @@ public ResponseSpec testNullableWithResponseSpec(ChildWithNullable childWithNull
23182402
return testNullableRequestCreation(childWithNullable);
23192403
}
23202404

2321-
@lombok.EqualsAndHashCode
23222405
public class TestQueryParameterCollectionFormatRequest {
23232406
private final List<String> pipe;
23242407
private final List<String> ioutil;
@@ -2396,6 +2479,21 @@ public TestQueryParameterCollectionFormatRequest language(Map<String, String> la
23962479
return this;
23972480
}
23982481

2482+
@Override
2483+
public boolean equals(Object o) {
2484+
if (this == o) {
2485+
return true;
2486+
}
2487+
if (o == null || getClass() != o.getClass()) {
2488+
return false;
2489+
}
2490+
return true;
2491+
}
2492+
2493+
@Override
2494+
public int hashCode() {
2495+
return Objects.hash();
2496+
}
23992497
}
24002498

24012499
/**

0 commit comments

Comments
 (0)