Skip to content

Commit 949880c

Browse files
committed
merge #23677 [KOTLIN-SPRING] Feature - add support for 'useDeductionForOneOfInterfaces'
1 parent d4804a0 commit 949880c

8 files changed

Lines changed: 17 additions & 8 deletions

File tree

docs/generators/java-camel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
109109
|title|server title name or client service name| |OpenAPI Spring|
110110
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
111111
|useBeanValidation|Use BeanValidation API annotations| |true|
112-
|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false|
112+
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
113113
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
114114
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
115115
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|

docs/generators/java-microprofile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9595
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
9696
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries| |false|
9797
|useBeanValidation|Use BeanValidation API annotations| |false|
98-
|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false|
98+
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
9999
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
100100
|useGzipFeature|Send gzip-encoded requests| |false|
101101
|useJackson3|Use Jackson 3 instead of Jackson 2. Supported for 'native' and 'apache-httpclient' libraries (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true).| |false|

docs/generators/java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9595
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
9696
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries| |false|
9797
|useBeanValidation|Use BeanValidation API annotations| |false|
98-
|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false|
98+
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
9999
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
100100
|useGzipFeature|Send gzip-encoded requests| |false|
101101
|useJackson3|Use Jackson 3 instead of Jackson 2. Supported for 'native' and 'apache-httpclient' libraries (requires Java 17+) and for Spring 'resttemplate', 'webclient', and 'restclient' libraries (require useSpringBoot4=true).| |false|

docs/generators/spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
102102
|title|server title name or client service name| |OpenAPI Spring|
103103
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|
104104
|useBeanValidation|Use BeanValidation API annotations| |true|
105-
|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false|
105+
|useDeductionForOneOfInterfaces|Annotate discriminator-free oneOf interfaces with Jackson's @JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype is resolved from the JSON field set rather than a type-tag property. Has no effect when a discriminator is present (name-based resolution is used instead). Requires subtypes to have structurally distinct sets of properties.| |false|
106106
|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false|
107107
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
108108
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
489489
public static final String X_MODEL_IS_MUTABLE = "x-model-is-mutable";
490490
public static final String X_IMPLEMENTS = "x-implements";
491491
public static final String X_IS_ONE_OF_INTERFACE = "x-is-one-of-interface";
492+
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces";
493+
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES_DESC =
494+
"Annotate discriminator-free oneOf interfaces with Jackson's " +
495+
"@JsonTypeInfo(use = Id.DEDUCTION) and @JsonSubTypes so the concrete subtype " +
496+
"is resolved from the JSON field set rather than a type-tag property. " +
497+
"Has no effect when a discriminator is present (name-based resolution is used instead). " +
498+
"Requires subtypes to have structurally distinct sets of properties.";
492499
public static final String X_DISCRIMINATOR_VALUE = "x-discriminator-value";
493500
public static final String X_ONE_OF_NAME = "x-one-of-name";
494501
public static final String X_NULLABLE = "x-nullable";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.util.stream.Stream;
7676
import java.util.stream.StreamSupport;
7777

78+
import static org.openapitools.codegen.CodegenConstants.USE_DEDUCTION_FOR_ONE_OF_INTERFACES;
7879
import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
7980
import static org.openapitools.codegen.utils.CamelizeOption.*;
8081
import static org.openapitools.codegen.utils.ModelUtils.getSchemaItems;
@@ -118,7 +119,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
118119
public static final String DEFAULT_TEST_FOLDER = "${project.build.directory}/generated-test-sources/openapi";
119120
public static final String GENERATE_CONSTRUCTOR_WITH_ALL_ARGS = "generateConstructorWithAllArgs";
120121
public static final String GENERATE_BUILDERS = "generateBuilders";
121-
public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces";
122122

123123
@Getter @Setter
124124
protected String dateLibrary = "java8";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
4949
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
5050
import static java.util.Collections.sort;
51-
import static org.openapitools.codegen.CodegenConstants.X_IMPLEMENTS;
51+
import static org.openapitools.codegen.CodegenConstants.*;
5252
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
5353
import static org.openapitools.codegen.utils.StringUtils.camelize;
5454

@@ -285,7 +285,7 @@ public JavaClientCodegen() {
285285
cliOptions.add(CliOption.newBoolean(USE_SEALED_ONE_OF_INTERFACES, "Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.", this.useSealedOneOfInterfaces));
286286
cliOptions.add(CliOption.newBoolean(USE_UNARY_INTERCEPTOR, "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", this.useUnaryInterceptor));
287287
cliOptions.add(CliOption.newBoolean(USE_JSPECIFY, "Use Jspecify for null checks. Only supported for " + JSPECIFY_SUPPORTED_LIBRARIES, useJspecify));
288-
cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, "whether to use deduction for generated oneOf interfaces", useDeductionForOneOfInterfaces));
288+
cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, USE_DEDUCTION_FOR_ONE_OF_INTERFACES_DESC, useDeductionForOneOfInterfaces));
289289

290290
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1");
291291
supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1");

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import java.util.stream.Collectors;
5555

5656
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
57+
import static org.openapitools.codegen.CodegenConstants.USE_DEDUCTION_FOR_ONE_OF_INTERFACES;
58+
import static org.openapitools.codegen.CodegenConstants.USE_DEDUCTION_FOR_ONE_OF_INTERFACES_DESC;
5759
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
5860
import static org.openapitools.codegen.utils.StringUtils.camelize;
5961

@@ -335,7 +337,7 @@ public SpringCodegen() {
335337
"Use `ofNullable` instead of just `of` to accept null values when using Optional.",
336338
optionalAcceptNullable));
337339

338-
cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, "whether to use deduction for generated oneOf interfaces", useDeductionForOneOfInterfaces));
340+
cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, USE_DEDUCTION_FOR_ONE_OF_INTERFACES_DESC, useDeductionForOneOfInterfaces));
339341
cliOptions.add(CliOption.newString(SPRING_API_VERSION, "Value for 'version' attribute in @RequestMapping (for Spring 7 and above)."));
340342
cliOptions.add(CliOption.newString(USE_HTTP_SERVICE_PROXY_FACTORY_INTERFACES_CONFIGURATOR,
341343
"Generate HttpInterfacesAbstractConfigurator based on an HttpServiceProxyFactory instance (as opposed to a WebClient instance, when disabled) for generating Spring HTTP interfaces.")

0 commit comments

Comments
 (0)