Skip to content

Commit 850ce3b

Browse files
authored
Merge branch 'OpenAPITools:master' into 20073-java-libraries-dependencies
2 parents 164ae13 + 2a17134 commit 850ce3b

File tree

68 files changed

+917
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+917
-51
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
- [ ] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
88
- [ ] Run the following to [build the project](https://github.com/OpenAPITools/openapi-generator#14---build-projects) and update samples:
99
```
10-
./mvnw clean package
11-
./bin/generate-samples.sh ./bin/configs/*.yaml
12-
./bin/utils/export_docs_generators.sh
10+
./mvnw clean package || exit
11+
./bin/generate-samples.sh ./bin/configs/*.yaml || exit
12+
./bin/utils/export_docs_generators.sh || exit
1313
```
1414
(For Windows users, please run the script in [Git BASH](https://gitforwindows.org/))
1515
Commit all changed files.

bin/configs/java-microprofile-rest-client-3.0-jackson.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ additionalProperties:
99
configKey: petstore
1010
microprofileRestClientVersion: "3.0"
1111
hideGenerationTimestamp: true
12+
useReflectionEqualsHashCode: true

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/model.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{{>licenseInfo}}
22
package {{package}};
33

4+
{{#useReflectionEqualsHashCode}}
5+
import org.apache.commons.lang3.builder.EqualsBuilder;
6+
import org.apache.commons.lang3.builder.HashCodeBuilder;
7+
{{/useReflectionEqualsHashCode}}
8+
import java.util.Objects;
9+
import java.util.Arrays;
410
{{#imports}}import {{import}};
511
{{/imports}}
612
{{#serializableModel}}

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,5 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi
148148
{{/isReadOnly}}
149149

150150
{{/vars}}
151-
152-
/**
153-
* Create a string representation of this pojo.
154-
*/
155-
@Override
156-
public String toString() {
157-
StringBuilder sb = new StringBuilder();
158-
sb.append("class {{classname}} {\n");
159-
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
160-
{{#vars}}sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
161-
{{/vars}}sb.append("}");
162-
return sb.toString();
163-
}
164-
165-
/**
166-
* Convert the given object to string with each line indented by 4 spaces
167-
* (except the first line).
168-
*/
169-
private static String toIndentedString(Object o) {
170-
if (o == null) {
171-
return "null";
172-
}
173-
return o.toString().replace("\n", "\n ");
174-
}
151+
{{>pojoOverrides}}
175152
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@Override
2+
public boolean equals(Object o) {
3+
{{#useReflectionEqualsHashCode}}
4+
return EqualsBuilder.reflectionEquals(this, o, false, null, true);
5+
{{/useReflectionEqualsHashCode}}
6+
{{^useReflectionEqualsHashCode}}
7+
if (this == o) {
8+
return true;
9+
}
10+
if (o == null || getClass() != o.getClass()) {
11+
return false;
12+
}{{#hasVars}}
13+
{{classname}} {{classVarName}} = ({{classname}}) o;
14+
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}} &&
15+
{{/-last}}{{/vars}}{{#parent}} &&
16+
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
17+
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
18+
{{/useReflectionEqualsHashCode}}
19+
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
20+
21+
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
22+
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
23+
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
24+
25+
@Override
26+
public int hashCode() {
27+
{{#useReflectionEqualsHashCode}}
28+
return HashCodeBuilder.reflectionHashCode(this);
29+
{{/useReflectionEqualsHashCode}}
30+
{{^useReflectionEqualsHashCode}}
31+
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}});
32+
{{/useReflectionEqualsHashCode}}
33+
}{{#vendorExtensions.x-jackson-optional-nullable-helpers}}
34+
35+
private static <T> int hashCodeNullable(JsonNullable<T> a) {
36+
if (a == null) {
37+
return 1;
38+
}
39+
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
40+
}{{/vendorExtensions.x-jackson-optional-nullable-helpers}}
41+
42+
/**
43+
* Create a string representation of this pojo.
44+
*/
45+
@Override
46+
public String toString() {
47+
StringBuilder sb = new StringBuilder();
48+
sb.append("class {{classname}} {\n");
49+
{{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
50+
{{#vars}}sb.append(" {{name}}: ").append({{#isPassword}}"*"{{/isPassword}}{{^isPassword}}toIndentedString({{name}}){{/isPassword}}).append("\n");
51+
{{/vars}}sb.append("}");
52+
return sb.toString();
53+
}
54+
55+
/**
56+
* Convert the given object to string with each line indented by 4 spaces
57+
* (except the first line).
58+
*/
59+
private static String toIndentedString(Object o) {
60+
if (o == null) {
61+
return "null";
62+
}
63+
return o.toString().replace("\n", "\n ");
64+
}

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pom.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@
196196
<version>${mutiny.version}</version>
197197
</dependency>
198198
{{/microprofileMutiny}}
199+
{{#useReflectionEqualsHashCode}}
200+
<!-- For equals and hashCode using reflection -->
201+
<dependency>
202+
<groupId>org.apache.commons</groupId>
203+
<artifactId>commons-lang3</artifactId>
204+
<version>${commons.lang3.version}</version>
205+
</dependency>
206+
{{/useReflectionEqualsHashCode}}
199207
</dependencies>
200208
<repositories>
201209
<repository>
@@ -210,6 +218,8 @@
210218
<java.version>1.8</java.version>
211219
<maven.compiler.source>${java.version}</maven.compiler.source>
212220
<maven.compiler.target>${java.version}</maven.compiler.target>
221+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
222+
213223
<swagger.core.version>1.5.18</swagger.core.version>
214224
<jetty.version>9.2.9.v20150224</jetty.version>
215225
<junit.version>5.10.2</junit.version>
@@ -238,9 +248,11 @@
238248
<jandex.maven.plugin.version>1.1.0</jandex.maven.plugin.version>
239249
<maven.failsafe.plugin.version>2.6</maven.failsafe.plugin.version>
240250
<build.helper.maven.plugin.version>1.9.1</build.helper.maven.plugin.version>
241-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
242251
{{#microprofileMutiny}}
243252
<mutiny.version>1.2.0</mutiny.version>
244253
{{/microprofileMutiny}}
254+
{{#useReflectionEqualsHashCode}}
255+
<commons.lang3.version>3.17.0</commons.lang3.version>
256+
{{/useReflectionEqualsHashCode}}
245257
</properties>
246258
</project>

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pom_3.0.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@
189189
<version>${jakarta.annotation.version}</version>
190190
<scope>provided</scope>
191191
</dependency>
192+
{{#useReflectionEqualsHashCode}}
193+
<!-- For equals and hashCode using reflection -->
194+
<dependency>
195+
<groupId>org.apache.commons</groupId>
196+
<artifactId>commons-lang3</artifactId>
197+
<version>${commons.lang3.version}</version>
198+
</dependency>
199+
{{/useReflectionEqualsHashCode}}
192200
</dependencies>
193201
<repositories>
194202
<repository>
@@ -203,6 +211,8 @@
203211
<java.version>11</java.version>
204212
<maven.compiler.source>${java.version}</maven.compiler.source>
205213
<maven.compiler.target>${java.version}</maven.compiler.target>
214+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
215+
206216
<swagger.core.version>1.5.18</swagger.core.version>
207217
<jetty.version>9.2.9.v20150224</jetty.version>
208218
<junit.version>5.10.2</junit.version>
@@ -231,6 +241,8 @@
231241
<jandex.maven.plugin.version>1.1.0</jandex.maven.plugin.version>
232242
<maven.failsafe.plugin.version>2.6</maven.failsafe.plugin.version>
233243
<build.helper.maven.plugin.version>1.9.1</build.helper.maven.plugin.version>
234-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
244+
{{#useReflectionEqualsHashCode}}
245+
<commons.lang3.version>3.17.0</commons.lang3.version>
246+
{{/useReflectionEqualsHashCode}}
235247
</properties>
236248
</project>

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ public class ApiClient {
987987
}
988988
{{/dynamicOperations}}
989989
990-
/**
990+
/**
991991
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
992992
*
993993
* @param value The free-form query parameters.
@@ -1001,6 +1001,7 @@ public class ApiClient {
10011001
return params;
10021002
}
10031003
1004+
@SuppressWarnings("unchecked")
10041005
final Map<String, Object> valuesMap = (Map<String, Object>) value;
10051006
10061007
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {

samples/client/echo_api/java/okhttp-gson-user-defined-templates/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
829829
return params;
830830
}
831831

832-
/**
832+
/**
833833
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
834834
*
835835
* @param value The free-form query parameters.
@@ -843,6 +843,7 @@ public List<Pair> freeFormParameterToPairs(Object value) {
843843
return params;
844844
}
845845

846+
@SuppressWarnings("unchecked")
846847
final Map<String, Object> valuesMap = (Map<String, Object>) value;
847848

848849
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {

samples/client/echo_api/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Collect
759759
return params;
760760
}
761761

762-
/**
762+
/**
763763
* Formats the specified free-form query parameters to a list of {@code Pair} objects.
764764
*
765765
* @param value The free-form query parameters.
@@ -773,6 +773,7 @@ public List<Pair> freeFormParameterToPairs(Object value) {
773773
return params;
774774
}
775775

776+
@SuppressWarnings("unchecked")
776777
final Map<String, Object> valuesMap = (Map<String, Object>) value;
777778

778779
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {

0 commit comments

Comments
 (0)