Skip to content

Commit 3bc4c27

Browse files
Merge branch 'master' into feature/jackson3-native
2 parents 9d5e569 + 80f2d7f commit 3bc4c27

357 files changed

Lines changed: 8896 additions & 740 deletions

File tree

Some content is hidden

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

.github/workflows/samples-java-client-jdk17.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
- samples/client/petstore/java/webclient-jakarta
3535
- samples/client/petstore/java/restclient
3636
- samples/client/petstore/java/restclient-nullable-arrays
37+
- samples/client/petstore/java/restclient-springBoot4-jackson2
38+
- samples/client/petstore/java/restclient-springBoot4-jackson3
3739
- samples/client/petstore/java/restclient-swagger2
3840
- samples/client/petstore/java/restclient-useSingleRequestParameter
3941
- samples/client/petstore/java/restclient-useSingleRequestParameter-static
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: java
2+
outputDir: samples/client/petstore/java/restclient-springBoot4-jackson2
3+
library: restclient
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/Java
6+
additionalProperties:
7+
artifactId: petstore-restclient
8+
hideGenerationTimestamp: "true"
9+
containerDefaultToNull: "true"
10+
useSpringBoot4: true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
generatorName: java
2+
outputDir: samples/client/petstore/java/restclient-springBoot4-jackson3
3+
library: restclient
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/Java
6+
additionalProperties:
7+
artifactId: petstore-restclient
8+
hideGenerationTimestamp: "true"
9+
containerDefaultToNull: "true"
10+
useSpringBoot4: true
11+
useJackson3: true
12+
openApiNullable: false

docs/generators/java-microprofile.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9797
|useBeanValidation|Use BeanValidation API annotations| |false|
9898
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
9999
|useGzipFeature|Send gzip-encoded requests| |false|
100-
|useJackson3|Use Jackson 3 instead of Jackson 2 for JSON processing. Only supported for 'native' library.| |false|
100+
|useJackson3|Use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
101101
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
102102
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
103103
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
@@ -108,6 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
108108
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
109109
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
110110
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
111+
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
111112
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
112113
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
113114
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|

docs/generators/java.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9797
|useBeanValidation|Use BeanValidation API annotations| |false|
9898
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
9999
|useGzipFeature|Send gzip-encoded requests| |false|
100-
|useJackson3|Use Jackson 3 instead of Jackson 2 for JSON processing. Only supported for 'native' library.| |false|
100+
|useJackson3|Use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
101101
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
102102
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
103103
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
@@ -108,6 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
108108
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
109109
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
110110
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
111+
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
111112
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
112113
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
113114
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
devShells.default = pkgs.mkShell
1414
{
1515
buildInputs = with pkgs;[
16-
jdk11
16+
jdk17
1717
maven
18+
gradle
1819
];
1920
};
2021
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public String getTypeDeclaration(Schema p) {
394394
inner = new StringSchema().description("TODO default missing map inner type to string");
395395
p.setAdditionalProperties(inner);
396396
}
397-
return getSchemaType(target) + "<kotlin.String, " + getTypeDeclaration(inner) + ">";
397+
return getSchemaType(target) + "<kotlin.String, " + getItemsTypeDeclaration(inner) + ">";
398398
}
399399
return super.getTypeDeclaration(target);
400400
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
4848
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
4949
import static java.util.Collections.sort;
50+
import static org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY;
5051
import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
5152
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
5253
import static org.openapitools.codegen.utils.StringUtils.camelize;
@@ -118,6 +119,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen
118119
public static final String SERIALIZATION_LIBRARY_JACKSON = "jackson";
119120
public static final String SERIALIZATION_LIBRARY_JSONB = "jsonb";
120121

122+
public static final String USE_SPRING_BOOT4 = "useSpringBoot4";
123+
public static final String USE_JACKSON_3 = "useJackson3";
124+
private static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
125+
private static final String JACKSON3_PACKAGE = "tools.jackson";
126+
private static final String JACKSON_PACKAGE = "jacksonPackage";
127+
121128
public static final String GENERATE_CLIENT_AS_BEAN = "generateClientAsBean";
122129

123130
protected String gradleWrapperPackage = "gradle.wrapper";
@@ -135,7 +142,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
135142
@Setter protected boolean microProfileRegisterExceptionMapper = true;
136143
@Setter protected String configKey = null;
137144
@Setter(AccessLevel.PRIVATE) protected boolean configKeyFromClassName = false;
138-
139145
@Setter protected boolean asyncNative = false;
140146
@Setter protected boolean parcelableModel = false;
141147
@Setter protected boolean performBeanValidation = false;
@@ -160,6 +166,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
160166
* Serialization library.
161167
*/
162168
@Getter protected String serializationLibrary = null;
169+
@Getter @Setter protected boolean useSpringBoot4 = false;
170+
@Getter @Setter protected boolean useJackson3 = false;
163171
@Setter protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
164172
protected String rootJavaEEPackage;
165173
protected Map<String, MpRestClientVersion> mpRestClientVersions = new LinkedHashMap<>();
@@ -301,8 +309,8 @@ public JavaClientCodegen() {
301309
serializationOptions.put(SERIALIZATION_LIBRARY_JSONB, "Use JSON-B as serialization library");
302310
serializationLibrary.setEnum(serializationOptions);
303311
cliOptions.add(serializationLibrary);
304-
305-
// Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
312+
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Generate code and provide dependencies for use with Spring Boot 4.x.", useSpringBoot4));
313+
cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Set it in order to use jackson 3 dependencies (only allowed when `" + USE_SPRING_BOOT4 + "` is set and incompatible with `"+OPENAPI_NULLABLE+"`).", useJackson3)); // Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
306314
// inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values,
307315
// and the discriminator mapping schemas in the OAS document.
308316
this.setLegacyDiscriminatorBehavior(false);
@@ -370,8 +378,24 @@ public void processOpts() {
370378
// default jackson unless overridden by setSerializationLibrary
371379
this.jackson = !additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY) ||
372380
SERIALIZATION_LIBRARY_JACKSON.equals(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));
373-
374381
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup);
382+
convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);
383+
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4);
384+
if(isUseJackson3() && !isUseSpringBoot4()){
385+
throw new IllegalArgumentException("useJackson3 is only available with Spring Boot >= 4");
386+
}
387+
if(isUseJackson3() && isOpenApiNullable()){
388+
throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3");
389+
}
390+
391+
if(this.useJackson3){
392+
this.applyJackson3Package();
393+
} else {
394+
this.applyJackson2Package();
395+
}
396+
397+
// override parent one
398+
importMapping.put("JsonDeserialize", (useJackson3 ? JACKSON3_PACKAGE : JACKSON2_PACKAGE) + ".databind.annotation.JsonDeserialize");
375399

376400
// RxJava
377401
if (additionalProperties.containsKey(USE_RX_JAVA2) && additionalProperties.containsKey(USE_RX_JAVA3)) {
@@ -799,8 +823,10 @@ public void processOpts() {
799823
additionalProperties.remove(SERIALIZATION_LIBRARY_GSON);
800824
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
801825
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
802-
supportingFiles.add(new SupportingFile("RFC3339InstantDeserializer.mustache", invokerFolder, "RFC3339InstantDeserializer.java"));
803-
supportingFiles.add(new SupportingFile("RFC3339JavaTimeModule.mustache", invokerFolder, "RFC3339JavaTimeModule.java"));
826+
if (!useJackson3) {
827+
supportingFiles.add(new SupportingFile("RFC3339InstantDeserializer.mustache", invokerFolder, "RFC3339InstantDeserializer.java"));
828+
supportingFiles.add(new SupportingFile("RFC3339JavaTimeModule.mustache", invokerFolder, "RFC3339JavaTimeModule.java"));
829+
}
804830
break;
805831
case SERIALIZATION_LIBRARY_GSON:
806832
additionalProperties.put(SERIALIZATION_LIBRARY_GSON, "true");
@@ -818,7 +844,7 @@ public void processOpts() {
818844
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
819845
break;
820846
}
821-
847+
822848
if (isLibrary(FEIGN)) {
823849
additionalProperties.put("feign-okhttp", "true");
824850
} else if (isLibrary(FEIGN_HC5)) {
@@ -1037,6 +1063,7 @@ private static boolean isMultipartType(List<Map<String, String>> consumes) {
10371063
@Override
10381064
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
10391065
super.postProcessModelProperty(model, property);
1066+
10401067
if (!model.isEnum) {
10411068
//Needed imports for Jackson based libraries
10421069
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
@@ -1252,6 +1279,14 @@ public void setCaseInsensitiveResponseHeaders(final Boolean caseInsensitiveRespo
12521279
this.caseInsensitiveResponseHeaders = caseInsensitiveResponseHeaders;
12531280
}
12541281

1282+
protected void applyJackson2Package() {
1283+
writePropertyBack(JACKSON_PACKAGE, JACKSON2_PACKAGE);
1284+
}
1285+
1286+
protected void applyJackson3Package() {
1287+
writePropertyBack(JACKSON_PACKAGE, JACKSON3_PACKAGE);
1288+
}
1289+
12551290
public void setSerializationLibrary(String serializationLibrary) {
12561291
if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) {
12571292
this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON;
@@ -1292,7 +1327,7 @@ public String toApiVarName(String name) {
12921327

12931328
@Override
12941329
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
1295-
if(additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
1330+
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {
12961331
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
12971332
Map<String, String> oneImport = new HashMap<>();
12981333
oneImport.put("import", importMapping.get(i));

modules/openapi-generator/src/main/resources/Java/RFC3339DateFormat.mustache

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
{{>licenseInfo}}
22
package {{invokerPackage}};
33

4-
{{^useJackson3}}
5-
import com.fasterxml.jackson.databind.util.StdDateFormat;
6-
{{/useJackson3}}
7-
{{#useJackson3}}
8-
import tools.jackson.databind.util.StdDateFormat;
9-
{{/useJackson3}}
10-
114
import java.text.DateFormat;
125
import java.text.FieldPosition;
136
import java.text.ParsePosition;
147
import java.util.Date;
158
import java.text.DecimalFormat;
169
import java.util.GregorianCalendar;
1710
import java.util.TimeZone;
11+
import {{jacksonPackage}}.databind.util.StdDateFormat;
1812

1913
{{>generatedAnnotation}}
2014

0 commit comments

Comments
 (0)