Skip to content

Commit e1447bc

Browse files
authored
docs(spring): fix discriminator property defaults (#21767)
1 parent c134a8a commit e1447bc

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

docs/generators/java-camel.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
6868
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
6969
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
7070
|invokerPackage|root package for generated code| |org.openapitools.api|
71-
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
71+
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|false|
7272
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd><dt>**spring-http-interface**</dt><dd>Spring 6 HTTP interfaces (testing)</dd></dl>|spring-boot|
7373
|licenseName|The name of the license| |Unlicense|
7474
|licenseUrl|The URL of the license| |http://unlicense.org|
@@ -103,7 +103,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
103103
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
104104
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
105105
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
106-
|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|
106+
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |true|
107107
|useOptional|Use Optional container for optional parameters| |false|
108108
|useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true|
109109
|useSealed|Whether to generate sealed model interfaces and classes| |false|

docs/generators/spring.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
6161
|implicitHeadersRegex|Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true| |null|
6262
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
6363
|invokerPackage|root package for generated code| |org.openapitools.api|
64-
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
64+
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|false|
6565
|library|library template (sub-template)|<dl><dt>**spring-boot**</dt><dd>Spring-boot Server application.</dd><dt>**spring-cloud**</dt><dd>Spring-Cloud-Feign client with Spring-Boot auto-configured settings.</dd><dt>**spring-http-interface**</dt><dd>Spring 6 HTTP interfaces (testing)</dd></dl>|spring-boot|
6666
|licenseName|The name of the license| |Unlicense|
6767
|licenseUrl|The URL of the license| |http://unlicense.org|
@@ -96,7 +96,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9696
|useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true|
9797
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|
9898
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
99-
|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|
99+
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |true|
100100
|useOptional|Use Optional container for optional parameters| |false|
101101
|useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true|
102102
|useSealed|Whether to generate sealed model interfaces and classes| |false|

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ public SpringCodegen() {
188188
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
189189
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
190190

191+
// Enable discriminator-based oneOf interface generation by default
192+
useOneOfInterfaces = true;
193+
legacyDiscriminatorBehavior = false;
194+
updateOption(USE_ONE_OF_INTERFACES, String.valueOf(useOneOfInterfaces));
195+
updateOption(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR, String.valueOf(legacyDiscriminatorBehavior));
196+
191197
apiTestTemplateFiles.clear(); // TODO: add test template
192198

193199
// spring uses the jackson lib
@@ -365,9 +371,6 @@ public void processOpts() {
365371

366372
convertPropertyToTypeAndWriteBack(REQUEST_MAPPING_OPTION, RequestMappingMode::valueOf, this::setRequestMappingMode);
367373

368-
useOneOfInterfaces = true;
369-
legacyDiscriminatorBehavior = false;
370-
371374
// Please refrain from updating values of Config Options after super.ProcessOpts() is called
372375
super.processOpts();
373376

0 commit comments

Comments
 (0)