Skip to content

Commit 1c88b5c

Browse files
authored
Generate Classes Conforming to Google Java Format (#404)
Generates `enum` and `record` classes conforming _more_ to Google Java Format. The classes **MAY** still violate `google-java-format`, particularly unused imports. This only affects formatting of `enum` and `record` classes, and does not include any changes to functionality or behaviour.
1 parent a5ccf49 commit 1c88b5c

File tree

337 files changed

+1481
-1983
lines changed

Some content is hidden

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

337 files changed

+1481
-1983
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ authors:
55
given-names: "Christopher"
66
orcid: "https://orcid.org/0009-0002-1005-3942"
77
title: "OpenAPI to Java Records Mustache Templates"
8-
version: 2.9.0
8+
version: 2.9.1
99
date-released: 2025-01-06
1010
url: "https://github.com/Chrimle/openapi-to-java-records-mustache-templates"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The mustache templates are best acquired by importing the project as a dependenc
3737
<dependency>
3838
<groupId>io.github.chrimle</groupId>
3939
<artifactId>openapi-to-java-records-mustache-templates</artifactId>
40-
<version>2.9.0</version>
40+
<version>2.9.1</version>
4141
</dependency>
4242
```
4343
It is **strongly recommended** to import the project as a dependency. It has officially been published to:

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The mustache templates are best acquired by importing the project as a dependenc
3232
<dependency>
3333
<groupId>io.github.chrimle</groupId>
3434
<artifactId>openapi-to-java-records-mustache-templates</artifactId>
35-
<version>2.9.0</version>
35+
<version>2.9.1</version>
3636
</dependency>
3737
```
3838
It is **strongly recommended** to import the project as a dependency. It has officially been published to:

mustache-templates/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.chrimle</groupId>
88
<artifactId>openapi-to-java-records-mustache-templates-parent</artifactId>
9-
<version>2.9.0</version>
9+
<version>2.9.1</version>
1010
</parent>
1111

1212
<artifactId>openapi-to-java-records-mustache-templates</artifactId>

mustache-templates/src/main/resources/templates/generateBuilders.mustache

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@
5959
*/
6060
public {{classname}} build() {
6161
return new {{classname}}(
62-
{{#vars}}{{name}}{{^-last}},
63-
{{/-last}}{{/vars}}
64-
);
62+
{{#vars}}{{name}}{{^-last}},
63+
{{/-last}}{{/vars}});
6564
}
6665
}
6766

mustache-templates/src/main/resources/templates/modelEnum.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import com.fasterxml.jackson.annotation.JsonValue;
3232

3333
{{/jackson}}{{!
34-
}}{{#gson}}import java.io.IOException;
35-
import com.google.gson.JsonElement;
34+
}}{{#gson}}import com.google.gson.JsonElement;
3635
import com.google.gson.TypeAdapter;
3736
import com.google.gson.stream.JsonReader;
3837
import com.google.gson.stream.JsonWriter;
38+
import java.io.IOException;
3939

4040
{{/gson}}{{!
4141
}}{{#isUri}}import java.net.URI;
@@ -130,8 +130,8 @@ import com.google.gson.stream.JsonWriter;
130130
}
131131

132132
/**
133-
* Reads the <i>next</i> JSON-value from the {@code jsonReader} and converts it to a
134-
* {@link {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} }.
133+
* Reads the <i>next</i> JSON-value from the {@code jsonReader} and converts it to a {@link
134+
* {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} }.
135135
*
136136
* @param jsonReader to read the JSON-string from.
137137
* @return a {@link {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} }.

mustache-templates/src/main/resources/templates/pojo.mustache

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ import java.util.Set;
6060
}}{{vendorExtensions.x-field-extra-annotation}}
6161
{{/vendorExtensions.x-field-extra-annotation}}{{!
6262
}}@{{javaxPackage}}.annotation.{{#isNullable}}Nullable{{/isNullable}}{{^isNullable}}Nonnull{{/isNullable}}{{>useBeanValidation}} {{{datatypeWithEnum}}} {{name}}{{^-last}},
63-
{{/-last}}{{/vars}}{{^serializableModel}}){{/serializableModel}}{{#serializableModel}}
64-
) implements Serializable{{/serializableModel}} {
63+
{{/-last}}{{/vars}}){{#serializableModel}}
64+
implements Serializable{{/serializableModel}} {
6565
{{>serializableModel}}
6666
{{#gson}} /** A set containing the names of all instance fields defined in this class. */
6767
public static final HashSet<String> openapiFields =
@@ -70,17 +70,17 @@ import java.util.Set;
7070
{{/-last}}{{/allVars}}));
7171

7272
/** A set containing the names of all required fields defined in this class. */
73-
public static final HashSet<String> openapiRequiredFields =
74-
new HashSet<String>(
75-
Set.of({{#requiredVars}}"{{baseName}}"{{^-last}},
73+
public static final HashSet<String> openapiRequiredFields ={{#requiredVars}}{{#-first}}
74+
{{/-first}}{{/requiredVars}} new HashSet<String>({{#requiredVars}}{{#-first}}
75+
{{/-first}}{{/requiredVars}}Set.of({{#requiredVars}}"{{baseName}}"{{^-last}},
7676
{{/-last}}{{/requiredVars}}));
7777

7878
{{/gson}}
7979
public {{classname}}(
8080
{{#vars}}@{{javaxPackage}}.annotation.{{#isNullable}}Nullable{{/isNullable}}{{^isNullable}}{{#defaultValue}}Nullable{{/defaultValue}}{{^defaultValue}}Nonnull{{/defaultValue}}{{/isNullable}} final {{{datatypeWithEnum}}} {{name}}{{^-last}},
81-
{{/-last}}{{/vars}}) { {{#vars}}
82-
this.{{name}} = {{^defaultValue}}{{name}}{{/defaultValue}}{{#defaultValue}}Objects.requireNonNullElse({{name}}, {{{.}}}){{/defaultValue}};{{/vars}}
83-
}{{#generateBuilders}}{{>generateBuilders}}{{/generateBuilders}}{{!
81+
{{/-last}}{{/vars}}) {
82+
{{#vars}} this.{{name}} = {{^defaultValue}}{{name}}{{/defaultValue}}{{#defaultValue}}Objects.requireNonNullElse({{name}}, {{{.}}}){{/defaultValue}};
83+
{{/vars}} }{{#generateBuilders}}{{>generateBuilders}}{{/generateBuilders}}{{!
8484
Generate inner enum classes
8585
}}{{#vars}}{{#isEnum}}
8686

@@ -175,8 +175,8 @@ import java.util.Set;
175175
}
176176

177177
/**
178-
* Reads the <i>next</i> JSON-value from the {@code jsonReader} and converts it to a
179-
* {@link {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} }.
178+
* Reads the <i>next</i> JSON-value from the {@code jsonReader} and converts it to a {@link
179+
* {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} }.
180180
*
181181
* @param jsonReader to read the JSON-string from.
182182
* @return a {@link {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} }.
@@ -200,16 +200,18 @@ import java.util.Set;
200200
* @param jsonElement to validate.
201201
* @throws IOException if the JSON Element is not a valid {{classname}} object.
202202
*/
203-
public static void validateJsonElement(final JsonElement jsonElement) throws IOException { {{#requiredVars}}{{#-first}}
204-
if (jsonElement == null) {
203+
public static void validateJsonElement(final JsonElement jsonElement) throws IOException {
204+
{{#requiredVars}}{{#-first}}{{!
205+
}} if (jsonElement == null) {
205206
throw new IllegalArgumentException(
206207
String.format(
207208
"The required field(s) %s in {{{classname}}} is not found in the empty JSON string",
208209
{{classname}}.openapiRequiredFields.toString()));
209210
}
211+
210212
{{/-first}}{{/requiredVars}}{{!
211-
}}{{^hasChildren}}{{^isAdditionalPropertiesTrue}}
212-
for (final String key : jsonElement.getAsJsonObject().keySet()) {
213+
}}{{^hasChildren}}{{^isAdditionalPropertiesTrue}}{{!
214+
}} for (final String key : jsonElement.getAsJsonObject().keySet()) {
213215
if (!{{classname}}.openapiFields.contains(key)) {
214216
throw new IllegalArgumentException(
215217
String.format(
@@ -232,8 +234,7 @@ import java.util.Set;
232234
final JsonObject jsonObj = jsonElement.getAsJsonObject();
233235
{{/hasVars}}{{!
234236
}}{{#vars}}{{^required}}
235-
if (jsonObj.get("{{{baseName}}}") != null
236-
&& !jsonObj.get("{{{baseName}}}").isJsonNull()) { {{/required}}{{!
237+
if (jsonObj.get("{{{baseName}}}") != null && !jsonObj.get("{{{baseName}}}").isJsonNull()) { {{/required}}{{!
237238
}}{{^isModel}}{{^isEnumRef}}{{^isEnum}}
238239
{{^required}} {{/required}} if (!jsonObj.get("{{{baseName}}}").{{#isArray}}isJsonArray(){{/isArray}}{{^isContainer}}{{^isModel}}isJsonPrimitive(){{/isModel}}{{/isContainer}}) {
239240
{{^required}} {{/required}} throw new IllegalArgumentException(

mustache-templates/target/classes/templates/generateBuilders.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
}}{{!
1717
Source: openapi-to-java-records-mustache-templates
18-
Version: 2.9.0
18+
Version: 2.9.1
1919
Type: Custom
2020
Dependencies:
2121
- none
@@ -59,9 +59,8 @@
5959
*/
6060
public {{classname}} build() {
6161
return new {{classname}}(
62-
{{#vars}}{{name}}{{^-last}},
63-
{{/-last}}{{/vars}}
64-
);
62+
{{#vars}}{{name}}{{^-last}},
63+
{{/-last}}{{/vars}});
6564
}
6665
}
6766

mustache-templates/target/classes/templates/javadoc.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
}}{{!
1717
Source: openapi-to-java-records-mustache-templates
18-
Version: 2.9.0
18+
Version: 2.9.1
1919
Type: Custom
2020
Dependencies:
2121
- none

mustache-templates/target/classes/templates/licenseInfo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
}}{{!
1717
Source: openapi-to-java-records-mustache-templates
18-
Version: 2.9.0
18+
Version: 2.9.1
1919
Type: Override
2020
Dependencies:
2121
- none
@@ -39,6 +39,6 @@
3939
* openapi-to-java-records-mustache-templates. For further information,
4040
* questions, requesting features or reporting issues, please visit:
4141
* https://github.com/Chrimle/openapi-to-java-records-mustache-templates.
42-
* Generated with Version: 2.9.0
42+
* Generated with Version: 2.9.1
4343
*
4444
*/

0 commit comments

Comments
 (0)