Skip to content

Commit 3ecb490

Browse files
authored
[JAVA-SPRING;KOTLIN-SPRING] - add possibility to override x-implements and x-kotlin-implements via config options. (#22839)
* feature/add-skip-x-implements * feature/add-skip-x-implements * feature/add-x-implements-overrides support in tooling * add basic unit test for x-implements and x-implements-overrides * add implementation and unit test for schemaImplements * add "java.io.Serializable" directly via x-kotlin-implements * add schemaImplements and schemaImplementsFields support to kotlin-spring * add xImplementsSkip additional property * add xKotlinImplementsSkip and xKotlinImplementsFieldsSkip additional properties * add unit tests * add documentation * commit changes and add missing interface * add documentation * add output to samples * change logs * fix issue #22756 * revert unrelated formatting changes * nudge test rerun * implement feedback from CR * check compilation success * fix interfaces
1 parent 40a0f6f commit 3ecb490

293 files changed

Lines changed: 16388 additions & 845 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-jdk17.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
1515
# servers
1616
- samples/openapi3/server/petstore/springboot-3/**
17+
- samples/server/petstore/springboot-x-implements-skip/**
1718
- samples/server/petstore/java-camel/**
1819
- samples/server/petstore/java-helidon-server/v3/mp/**
1920
- samples/server/petstore/java-helidon-server/v3/se/**
@@ -31,6 +32,7 @@ on:
3132
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
3233
# servers
3334
- samples/openapi3/server/petstore/springboot-3/**
35+
- samples/server/petstore/springboot-x-implements-skip/**
3436
- samples/server/petstore/java-camel/**
3537
- samples/server/petstore/java-helidon-server/v3/mp/**
3638
- samples/server/petstore/java-helidon-server/v3/se/**
@@ -54,6 +56,7 @@ jobs:
5456
- samples/client/petstore/java/microprofile-rest-client-outer-enum
5557
# servers
5658
- samples/openapi3/server/petstore/springboot-3
59+
- samples/server/petstore/springboot-x-implements-skip
5760
- samples/server/petstore/java-camel/
5861
- samples/server/petstore/java-helidon-server/v3/mp/
5962
- samples/server/petstore/java-helidon-server/v3/se

bin/configs/kotlin-spring-boot-x-kotlin-implements.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@ additionalProperties:
1313
serializableModel: true
1414
beanValidations: true
1515
includeHttpRequestContext: true
16+
schemaImplements:
17+
Pet: com.some.pack.WithId
18+
Category: [ com.some.pack.CategoryInterface ]
19+
Dog: [ com.some.pack.Canine ]
20+
schemaImplementsFields:
21+
Pet: id
22+
Category: [ name, id ]
23+
Dog: [ bark, breed ]
24+
xKotlinImplementsSkip: [ com.some.pack.WithPhotoUrls ]
25+
xKotlinImplementsFieldsSkip:
26+
Pet: [ photoUrls ]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
generatorName: spring
2+
outputDir: samples/server/petstore/springboot-x-implements-skip
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/spring/petstore-with-fake-endpoints-models-for-testing-x-implements.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/JavaSpring
5+
additionalProperties:
6+
documentationProvider: springfox
7+
artifactId: springboot
8+
snapshotVersion: "true"
9+
hideGenerationTimestamp: "true"
10+
camelCaseDollarSign: "true"
11+
modelNameSuffix: 'Dto'
12+
xImplementsSkip: [ com.custompackage.InterfaceToSkip ]
13+
schemaImplements:
14+
Foo: [ com.custompackage.WithBar, com.custompackage.WithDefaultMethod ]
15+
Animal: com.custompackage.WithColor

docs/generators/java-camel.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8787
|resourceFolder|resource folder for generated resources| |src/main/resources|
8888
|responseWrapper|wrap the responses in given type (Future, Callable, CompletableFuture,ListenableFuture, DeferredResult, RxObservable, RxSingle or fully qualified type)| |null|
8989
|returnSuccessCode|Generated server returns 2xx code| |false|
90+
|schemaImplements|Ability to supply interfaces per schema that should be implemented (serves similar purpose as vendor extension `x-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)| |empty map|
9091
|scmConnection|SCM connection in generated pom.xml| |scm:git:git@github.com:openapitools/openapi-generator.git|
9192
|scmDeveloperConnection|SCM developer connection in generated pom.xml| |scm:git:git@github.com:openapitools/openapi-generator.git|
9293
|scmUrl|SCM URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
@@ -118,6 +119,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
118119
|useTags|use tags for creating interface and controller classnames| |false|
119120
|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false|
120121
|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|
122+
|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|
121123

122124
## SUPPORTED VENDOR EXTENSIONS
123125

docs/generators/kotlin-spring.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4343
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
4444
|reactive|use coroutines for reactive behavior| |false|
4545
|requestMappingMode|Where to generate the class level @RequestMapping annotation.|<dl><dt>**api_interface**</dt><dd>Generate the @RequestMapping annotation on the generated Api Interface.</dd><dt>**controller**</dt><dd>Generate the @RequestMapping annotation on the generated Api Controller Implementation.</dd><dt>**none**</dt><dd>Do not add a class level @RequestMapping annotation.</dd></dl>|controller|
46+
|schemaImplements|A map of single interface or a list of interfaces per schema name that should be implemented (serves similar purpose as `x-kotlin-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)| |empty map|
47+
|schemaImplementsFields|A map of single field or a list of fields per schema name that should be prepended with `override` (serves similar purpose as `x-kotlin-implements-fields`, but is fully decoupled from the api spec). Example: yaml `schemaImplementsFields: {Pet: id, Category: [name, id], Dog: [bark, breed]}` marks fields to be prepended with `override` in schemas `Pet` (field `id`), `Category` (fields `name`, `id`) and `Dog` (fields `bark`, `breed`)| |empty map|
4648
|serializableModel|boolean - toggle &quot;implements Serializable&quot; for generated models| |null|
4749
|serverPort|configuration the port in which the sever is to run on| |8080|
4850
|serviceImplementation|generate stub service implementations that extends service interfaces. If this is set to true service interfaces will also be generated| |false|
@@ -59,6 +61,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5961
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot &ge; 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
6062
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
6163
|useTags|Whether to use tags for creating interface and controller class names| |false|
64+
|xKotlinImplementsFieldsSkip|A list of fields per schema name that should NOT be created with `override` keyword despite their presence in vendor extension `x-kotlin-implements-fields` for the schema. Example: yaml `xKotlinImplementsFieldsSkip: Pet: [photoUrls]` skips `override` for `photoUrls` in schema `Pet`| |empty map|
65+
|xKotlinImplementsSkip|A list of fully qualified interfaces that should NOT be implemented despite their presence in vendor extension `x-kotlin-implements`. Example: yaml `xKotlinImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface in any schema| |empty list|
6266

6367
## SUPPORTED VENDOR EXTENSIONS
6468

docs/generators/spring.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8080
|resourceFolder|resource folder for generated resources| |src/main/resources|
8181
|responseWrapper|wrap the responses in given type (Future, Callable, CompletableFuture,ListenableFuture, DeferredResult, RxObservable, RxSingle or fully qualified type)| |null|
8282
|returnSuccessCode|Generated server returns 2xx code| |false|
83+
|schemaImplements|Ability to supply interfaces per schema that should be implemented (serves similar purpose as vendor extension `x-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)| |empty map|
8384
|scmConnection|SCM connection in generated pom.xml| |scm:git:git@github.com:openapitools/openapi-generator.git|
8485
|scmDeveloperConnection|SCM developer connection in generated pom.xml| |scm:git:git@github.com:openapitools/openapi-generator.git|
8586
|scmUrl|SCM URL in generated pom.xml| |https://github.com/openapitools/openapi-generator|
@@ -111,6 +112,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
111112
|useTags|use tags for creating interface and controller classnames| |false|
112113
|virtualService|Generates the virtual service. For more details refer - https://github.com/virtualansoftware/virtualan/wiki| |false|
113114
|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|
115+
|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|
114116

115117
## SUPPORTED VENDOR EXTENSIONS
116118

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public static CliOption newString(String opt, String description) {
112112
return new CliOption(opt, description, SchemaTypeUtil.STRING_TYPE);
113113
}
114114

115+
public static CliOption newString(String opt, String description, String defaultValue) {
116+
return new CliOption(opt, description, SchemaTypeUtil.STRING_TYPE).defaultValue(String.valueOf(defaultValue));
117+
}
118+
115119
@JsonIgnore
116120
public String getOptionHelp() {
117121
StringBuilder sb = new StringBuilder(description);

0 commit comments

Comments
 (0)