Skip to content

Commit 2f06df2

Browse files
committed
Move the cliOption to the OpenAPINormalizer
1 parent 621c3da commit 2f06df2

15 files changed

Lines changed: 289 additions & 272 deletions

File tree

docs/customization.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,47 @@ index 6f27abd..146c61c 100644
681681
type: string
682682
```
683683

684+
- `USE_UNWRAPPED_FOR_INLINE_ONEOF` set to true to unwrap inline oneOf combined with allOf/properties and without discriminator (aka mixed oneOf). Set the vendorExtension X_ONE_OF_UNWRAPPED to be used by generators. For example the java generator annotates the new oneOf property with the jackson `@JsonUnwrapped` annotation
685+
686+
Example:
687+
```
688+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/oneOf_unwrap_mixed.yaml -o /tmp/java/ --openapi-normalizer X_ONE_OF_UNWRAPPED=true
689+
```
690+
691+
Here is what the change in the spec looks like:
692+
```diff
693+
diff --git a/api/openapi.yaml b/api/openapi.yaml
694+
index 6f27abd..146c61c 100644
695+
--- a/api/openapi.yaml
696+
+++ b/api/openapi.yaml
697+
@@ -9,10 +9,10 @@ components:
698+
schemas:
699+
Account:
700+
- oneOf:
701+
- - properties:
702+
- bankNumber:
703+
- type: string
704+
- bic:
705+
- type: string
706+
- - properties:
707+
- iban:
708+
- type: string
709+
properties:
710+
bank:
711+
$ref: '#/components/schemas/Bank'
712+
+ oneOf:
713+
+ X_ONE_OF_UNWRAPPED: true
714+
+ oneOf:
715+
+ - properties:
716+
+ bankNumber:
717+
+ type: string
718+
+ bic:
719+
+ type: string
720+
+ - properties:
721+
+ iban:
722+
+ type: string
723+
```
724+
684725
- `FILTER`
685726

686727
The `FILTER` parameter allows selective inclusion of API operations based on specific criteria. It applies the `x-internal: true` property to operations that do **not** match the specified values, preventing them from being generated. Multiple filters can be separated by a semicolon.

docs/generators/java-camel.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
127127
|useSpringController|Annotate the generated API as a Spring Controller| |false|
128128
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
129129
|useTags|use tags for creating interface and controller classnames| |false|
130-
|useWrapperForMixedOneOf|whether to use jackson @JsonUnwrapped and a Wrapper interface for inline oneOf combined with allOf/properties and without discriminator| |false|
131130
|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false|
132131
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
133132
|xImplementsSkip|Ability to choose interfaces that should NOT be implemented in the models despite their presence in vendor extension `x-implements`. Takes a list of fully qualified interface names. Example: yaml `xImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface `com.some.pack.WithPhotoUrls` in any schema| |empty list|

docs/generators/java-microprofile.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
113113
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
114114
|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|
115115
|useVertx5|Whether to use Vert.x 5 syntax.| |false|
116-
|useWrapperForMixedOneOf|whether to use jackson @JsonUnwrapped and a Wrapper interface for inline oneOf combined with allOf/properties and without discriminator| |false|
117116
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
118117
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|
119118
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|

docs/generators/java.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
113113
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
114114
|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|
115115
|useVertx5|Whether to use Vert.x 5 syntax.| |false|
116-
|useWrapperForMixedOneOf|whether to use jackson @JsonUnwrapped and a Wrapper interface for inline oneOf combined with allOf/properties and without discriminator| |false|
117116
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
118117
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|
119118
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|

docs/generators/spring.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
120120
|useSpringController|Annotate the generated API as a Spring Controller| |false|
121121
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
122122
|useTags|use tags for creating interface and controller classnames| |false|
123-
|useWrapperForMixedOneOf|whether to use jackson @JsonUnwrapped and a Wrapper interface for inline oneOf combined with allOf/properties and without discriminator| |false|
124123
|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false|
125124
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
126125
|xImplementsSkip|Ability to choose interfaces that should NOT be implemented in the models despite their presence in vendor extension `x-implements`. Takes a list of fully qualified interface names. Example: yaml `xImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface `com.some.pack.WithPhotoUrls` in any schema| |empty list|

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
499499
public static final String X_DISCRIMINATOR_VALUE = "x-discriminator-value";
500500
public static final String X_ONE_OF_NAME = "x-one-of-name";
501501
public static final String X_NULLABLE = "x-nullable";
502+
503+
public static final String X_ONE_OF_JSON_CREATOR = "x-oneof-jsonCreator";
504+
public static final String X_ONE_OF_UNWRAPPED = "x-oneOfunwrapper";
502505
}

0 commit comments

Comments
 (0)