Skip to content

Commit ae9027d

Browse files
committed
Use the same options as server generator
1 parent 54ad51c commit ae9027d

413 files changed

Lines changed: 26258 additions & 68 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.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
generatorName: java
2-
outputDir: samples/client/petstore/java/restclient-spring-7
2+
outputDir: samples/client/petstore/java/restclient-springBoot4-jackson2
33
library: restclient
44
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
55
templateDir: modules/openapi-generator/src/main/resources/Java
66
additionalProperties:
77
artifactId: petstore-restclient
88
hideGenerationTimestamp: "true"
99
containerDefaultToNull: "true"
10-
useSpring7: 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-with-fake-endpoints-models-for-testing.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,6 +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|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
100101
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
101102
|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|
102103
|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|
@@ -107,7 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
107108
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
108109
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
109110
|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|
110-
|useSpring7|Generate code and provide dependencies for use with Spring 7.x. (Use jackson 3).| |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,6 +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|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
100101
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
101102
|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|
102103
|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|
@@ -107,7 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
107108
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
108109
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
109110
|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|
110-
|useSpring7|Generate code and provide dependencies for use with Spring 7.x. (Use jackson 3).| |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|

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
118118
public static final String SERIALIZATION_LIBRARY_JACKSON = "jackson";
119119
public static final String SERIALIZATION_LIBRARY_JSONB = "jsonb";
120120

121-
public static final String USE_SPRING_7 = "useSpring7";
121+
public static final String USE_SPRING_BOOT4 = "useSpringBoot4";
122+
public static final String USE_JACKSON_3 = "useJackson3";
122123
private static final String JACKSON2_PACKAGE = "com.fasterxml.jackson";
123124
private static final String JACKSON3_PACKAGE = "tools.jackson";
124125
private static final String JACKSON_PACKAGE = "jacksonPackage";
@@ -163,7 +164,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
163164
* Serialization library.
164165
*/
165166
@Getter protected String serializationLibrary = null;
166-
@Getter @Setter protected boolean useSpring7 = false;
167+
@Getter @Setter protected boolean useSpringBoot4 = false;
168+
@Getter @Setter protected boolean useJackson3 = false;
167169
@Setter protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
168170
protected String rootJavaEEPackage;
169171
protected Map<String, MpRestClientVersion> mpRestClientVersions = new LinkedHashMap<>();
@@ -304,10 +306,8 @@ public JavaClientCodegen() {
304306
serializationOptions.put(SERIALIZATION_LIBRARY_JSONB, "Use JSON-B as serialization library");
305307
serializationLibrary.setEnum(serializationOptions);
306308
cliOptions.add(serializationLibrary);
307-
cliOptions.add(CliOption.newBoolean(USE_SPRING_7,
308-
"Generate code and provide dependencies for use with Spring 7.x. (Use jackson 3).",
309-
useSpring7));
310-
// Ensure the OAS 3.x discriminator mappings include any descendent schemas that allOf
309+
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Generate code and provide dependencies for use with Spring Boot 4.x.", useSpringBoot4));
310+
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
311311
// inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values,
312312
// and the discriminator mapping schemas in the OAS document.
313313
this.setLegacyDiscriminatorBehavior(false);
@@ -376,13 +376,24 @@ public void processOpts() {
376376
this.jackson = !additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY) ||
377377
SERIALIZATION_LIBRARY_JACKSON.equals(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));
378378
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup);
379-
convertPropertyToBooleanAndWriteBack(USE_SPRING_7, this::setUseSpring7);
380-
if(this.useSpring7){
379+
convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);
380+
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4);
381+
if(isUseJackson3() && !isUseSpringBoot4()){
382+
throw new IllegalArgumentException("useJackson3 is only available with Spring Boot >= 4");
383+
}
384+
if(isUseJackson3() && isOpenApiNullable()){
385+
throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3");
386+
}
387+
388+
if(this.useJackson3){
381389
this.applyJackson3Package();
382390
} else {
383391
this.applyJackson2Package();
384392
}
385393

394+
// override parent one
395+
importMapping.put("JsonDeserialize", (useJackson3 ? JACKSON3_PACKAGE : JACKSON2_PACKAGE) + ".databind.annotation.JsonDeserialize");
396+
386397
// RxJava
387398
if (additionalProperties.containsKey(USE_RX_JAVA2) && additionalProperties.containsKey(USE_RX_JAVA3)) {
388399
LOGGER.warn("You specified all RxJava versions 2 and 3 but they are mutually exclusive. Defaulting to v3.");
@@ -698,10 +709,6 @@ public void processOpts() {
698709
// The flag below should be set for all Java libraries, but the templates need to be ported
699710
// one by one for each library.
700711
supportsAdditionalPropertiesWithComposedSchema = true;
701-
if (useSpring7) {
702-
// currently not supported for spring7 (neither for Jackson nor JSON-B)
703-
openApiNullable = false;
704-
}
705712
} else if (libVertx) {
706713
typeMapping.put("file", "AsyncFile");
707714
importMapping.put("AsyncFile", "io.vertx.core.file.AsyncFile");
@@ -807,7 +814,7 @@ public void processOpts() {
807814
additionalProperties.remove(SERIALIZATION_LIBRARY_GSON);
808815
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
809816
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
810-
if (!useSpring7) {
817+
if (!useJackson3) {
811818
supportingFiles.add(new SupportingFile("RFC3339InstantDeserializer.mustache", invokerFolder, "RFC3339InstantDeserializer.java"));
812819
supportingFiles.add(new SupportingFile("RFC3339JavaTimeModule.mustache", invokerFolder, "RFC3339JavaTimeModule.java"));
813820
}
@@ -1048,9 +1055,6 @@ private static boolean isMultipartType(List<Map<String, String>> consumes) {
10481055
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
10491056
super.postProcessModelProperty(model, property);
10501057

1051-
if (useSpring7) {
1052-
importMapping.put("JsonDeserialize", "tools.jackson.databind.annotation.JsonDeserialize");
1053-
}
10541058
if (!model.isEnum) {
10551059
//Needed imports for Jackson based libraries
10561060
if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON)) {

0 commit comments

Comments
 (0)