Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/samples-kotlin-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
- samples/client/echo_api/kotlin-jvm-spring-3-restclient
- samples/client/others/kotlin-jvm-spring-3-restclient-nullable-return
- samples/client/petstore/kotlin-jvm-spring-4-restclient-jackson3
- samples/client/petstore/kotlin-jvm-spring-4-webclient-jackson3
- samples/client/petstore/kotlin-name-parameter-mappings
- samples/client/others/kotlin-jvm-okhttp-parameter-tests
- samples/client/others/kotlin-jvm-okhttp-path-comments
Expand Down
10 changes: 10 additions & 0 deletions bin/configs/kotlin-jvm-spring-4-webclient-jackson3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: kotlin
outputDir: samples/client/petstore/kotlin-jvm-spring-4-webclient-jackson3
library: jvm-spring-webclient
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
artifactId: kotlin-petstore-spring4-webclient-jackson3
enumUnknownDefaultCase: true
serializationLibrary: jackson
useSpringBoot4: true
6 changes: 3 additions & 3 deletions docs/generators/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools|
|idea|Add IntelliJ Idea plugin and mark Kotlin main and test folders as source folders.| |false|
|implicitHeaders|Skip header parameters in the generated API methods.| |false|
|library|Library template (sub-template) to use|<dl><dt>**jvm-ktor**</dt><dd>Platform: Java Virtual Machine. HTTP client: Ktor 1.6.7. JSON processing: Gson, Jackson (default).</dd><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-spring-webclient**</dt><dd>Platform: Java Virtual Machine. HTTP: Spring 5 (or 6 with useSpringBoot3 enabled) WebClient. JSON processing: Jackson.</dd><dt>**jvm-spring-restclient**</dt><dd>Platform: Java Virtual Machine. HTTP: Spring 6 (or 7 with useSpringBoot4 enabled) RestClient. JSON processing: Jackson.</dd><dt>**jvm-retrofit2**</dt><dd>Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.7. JSON processing: Kotlinx Serialization: 1.2.1.</dd><dt>**jvm-volley**</dt><dd>Platform: JVM for Android. HTTP client: Volley 1.2.1. JSON processing: gson 2.8.9 (Deprecated)</dd><dt>**jvm-vertx**</dt><dd>Platform: Java Virtual Machine. HTTP client: Vert.x Web Client. JSON processing: Moshi, Gson or Jackson.</dd><dt>**jvm-microprofile**</dt><dd>Platform: Java Virtual Machine. HTTP client: MicroProfile Rest Client 3.0 (Jakarta) or 2.0 (javax). JSON processing: Jackson. Optional SmallRye Mutiny support.</dd></dl>|jvm-okhttp4|
|library|Library template (sub-template) to use|<dl><dt>**jvm-ktor**</dt><dd>Platform: Java Virtual Machine. HTTP client: Ktor 1.6.7. JSON processing: Gson, Jackson (default).</dd><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-spring-webclient**</dt><dd>Platform: Java Virtual Machine. HTTP: Spring 5 (or 6 with useSpringBoot3, 7 with useSpringBoot4 enabled) WebClient. JSON processing: Jackson.</dd><dt>**jvm-spring-restclient**</dt><dd>Platform: Java Virtual Machine. HTTP: Spring 6 (or 7 with useSpringBoot4 enabled) RestClient. JSON processing: Jackson.</dd><dt>**jvm-retrofit2**</dt><dd>Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.7. JSON processing: Kotlinx Serialization: 1.2.1.</dd><dt>**jvm-volley**</dt><dd>Platform: JVM for Android. HTTP client: Volley 1.2.1. JSON processing: gson 2.8.9 (Deprecated)</dd><dt>**jvm-vertx**</dt><dd>Platform: Java Virtual Machine. HTTP client: Vert.x Web Client. JSON processing: Moshi, Gson or Jackson.</dd><dt>**jvm-microprofile**</dt><dd>Platform: Java Virtual Machine. HTTP client: MicroProfile Rest Client 3.0 (Jakarta) or 2.0 (javax). JSON processing: Jackson. Optional SmallRye Mutiny support.</dd></dl>|jvm-okhttp4|
|mapFileBinaryToByteArray|Map File and Binary to ByteArray (default: false)| |false|
|microprofileMutiny|Return SmallRye Mutiny Uni types with jvm-microprofile. This library does not support useCoroutines or useRxJava3.| |false|
|microprofileRestClientVersion|MicroProfile Rest Client API version for jvm-microprofile. Supported values: 2.0 (javax, useJakartaEe=false), 3.0 (Jakarta, useJakartaEe=true). If specified, useJakartaEe must match the version.| |3.0|
Expand All @@ -57,13 +57,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|supportAndroidApiLevel25AndBelow|[WARNING] This flag will generate code that has a known security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in order to support Android API level 25 and below. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284| |false|
|typeInfoDefaultImpls|Map of schema name to default Jackson deserialization class for @JsonTypeInfo(defaultImpl=...). For kotlin-client this applies to discriminator-based oneOf interfaces only (deduction-based oneOf is not supported by the kotlin-client templates). Overrides x-jackson-default-impl when both are set for the same schema. Requires the jackson serialization library. Example: yaml `typeInfoDefaultImpls: {PostRegistrationRequest: PostRegistrationBasicRequest}`| |empty map|
|useCoroutines|Whether to use the Coroutines adapter with the retrofit2 library.| |false|
|useJackson3|Use Jackson 3 dependencies (tools.jackson package). Requires serializationLibrary=jackson. Incompatible with openApiNullable.| |false|
|useJackson3|Use Jackson 3 dependencies (tools.jackson package). Requires serializationLibrary=jackson. Incompatible with openApiNullable. Supported by jvm-okhttp4, jvm-spring-restclient and jvm-spring-webclient; for the Spring libraries it requires useSpringBoot4 and defaults to true when useSpringBoot4 is enabled.| |false|
|useNonAsciiHeaders|Allow to use non-ascii headers with the okhttp library| |false|
|useResponseAsReturnType|When using retrofit2 and coroutines, use `Response`&lt;`T`&gt; as return type instead of `T`.| |true|
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library.| |false|
|useSettingsGradle|Whether the project uses settings.gradle.| |false|
|useSpringBoot3|Whether to use the Spring Boot 3 with the jvm-spring-webclient library.| |false|
|useSpringBoot4|Whether to use the Spring Boot 4 with the jvm-spring-restclient library.| |false|
|useSpringBoot4|Whether to use the Spring Boot 4 with the jvm-spring-webclient and jvm-spring-restclient libraries.| |false|

## SUPPORTED VENDOR EXTENSIONS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public KotlinClientCodegen() {

supportedLibraries.put(JVM_KTOR, "Platform: Java Virtual Machine. HTTP client: Ktor 1.6.7. JSON processing: Gson, Jackson (default).");
supportedLibraries.put(JVM_OKHTTP4, "[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.");
supportedLibraries.put(JVM_SPRING_WEBCLIENT, "Platform: Java Virtual Machine. HTTP: Spring 5 (or 6 with useSpringBoot3 enabled) WebClient. JSON processing: Jackson.");
supportedLibraries.put(JVM_SPRING_WEBCLIENT, "Platform: Java Virtual Machine. HTTP: Spring 5 (or 6 with useSpringBoot3, 7 with useSpringBoot4 enabled) WebClient. JSON processing: Jackson.");
supportedLibraries.put(JVM_SPRING_RESTCLIENT, "Platform: Java Virtual Machine. HTTP: Spring 6 (or 7 with useSpringBoot4 enabled) RestClient. JSON processing: Jackson.");
supportedLibraries.put(JVM_RETROFIT2, "Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.");
supportedLibraries.put(MULTIPLATFORM, "Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.7. JSON processing: Kotlinx Serialization: 1.2.1.");
Expand All @@ -288,7 +288,7 @@ public KotlinClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA3, "Whether to use the RxJava3 adapter with the retrofit2 library."));
cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines adapter with the retrofit2 library."));
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT3, "Whether to use the Spring Boot 3 with the jvm-spring-webclient library."));
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Whether to use the Spring Boot 4 with the jvm-spring-restclient library."));
cliOptions.add(CliOption.newBoolean(USE_SPRING_BOOT4, "Whether to use the Spring Boot 4 with the jvm-spring-webclient and jvm-spring-restclient libraries."));
cliOptions.add(CliOption.newBoolean(OMIT_GRADLE_PLUGIN_VERSIONS, "Whether to declare Gradle plugin versions in build files."));
cliOptions.add(CliOption.newBoolean(OMIT_GRADLE_WRAPPER, "Whether to omit Gradle wrapper for creating a sub project."));
cliOptions.add(CliOption.newBoolean(USE_SETTINGS_GRADLE, "Whether the project uses settings.gradle."));
Expand Down Expand Up @@ -330,7 +330,7 @@ public KotlinClientCodegen() {
cliOptions.add(new CliOption(CONFIG_KEY, "Configuration key in @RegisterRestClient for jvm-microprofile. Mutually exclusive with configKeyFromClassName=true."));
cliOptions.add(CliOption.newBoolean(CONFIG_KEY_FROM_CLASS_NAME, "Derive the jvm-microprofile configuration key from the API class name. Mutually exclusive with configKey.", false));

cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 dependencies (tools.jackson package). Requires serializationLibrary=jackson. Incompatible with openApiNullable."));
cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 dependencies (tools.jackson package). Requires serializationLibrary=jackson. Incompatible with openApiNullable. Supported by jvm-okhttp4, jvm-spring-restclient and jvm-spring-webclient; for the Spring libraries it requires useSpringBoot4 and defaults to true when useSpringBoot4 is enabled."));

// AbstractKotlinCodegen calls cliOptions.clear(), dropping DefaultCodegen's registration.
// Re-registered on kotlin alone: no other Kotlin generator's templates implement the fallback.
Expand Down Expand Up @@ -523,7 +523,8 @@ public void processOpts() {

boolean useSpringBoot4 = additionalProperties.containsKey(USE_SPRING_BOOT4)
&& convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4);
if (JVM_SPRING_RESTCLIENT.equals(getLibrary()) && useSpringBoot4 && !useJackson3Configured) {
if ((JVM_SPRING_RESTCLIENT.equals(getLibrary()) || JVM_SPRING_WEBCLIENT.equals(getLibrary()))
&& useSpringBoot4 && !useJackson3Configured) {
setUseJackson3(true);
additionalProperties.put(USE_JACKSON_3, true);
applyJackson3Package();
Expand All @@ -544,11 +545,11 @@ public void processOpts() {
&& Boolean.parseBoolean(additionalProperties.get("openApiNullable").toString())) {
throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3");
}
if (!JVM_OKHTTP4.equals(getLibrary()) && !JVM_SPRING_RESTCLIENT.equals(getLibrary())) {
throw new IllegalArgumentException("useJackson3 is only supported for the jvm-okhttp4 and jvm-spring-restclient libraries at this time.");
if (!JVM_OKHTTP4.equals(getLibrary()) && !JVM_SPRING_RESTCLIENT.equals(getLibrary()) && !JVM_SPRING_WEBCLIENT.equals(getLibrary())) {
throw new IllegalArgumentException("useJackson3 is only supported for the jvm-okhttp4, jvm-spring-restclient and jvm-spring-webclient libraries at this time.");
}
if (JVM_SPRING_RESTCLIENT.equals(getLibrary()) && !useSpringBoot4) {
throw new IllegalArgumentException("useJackson3 with jvm-spring-restclient requires useSpringBoot4=true.");
if ((JVM_SPRING_RESTCLIENT.equals(getLibrary()) || JVM_SPRING_WEBCLIENT.equals(getLibrary())) && !useSpringBoot4) {
throw new IllegalArgumentException("useJackson3 with " + getLibrary() + " requires useSpringBoot4=true.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ kotlin {
}
{{/explicitApi}}
{{#jvm-spring-webclient}}
{{#useSpringBoot4}}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
{{/useSpringBoot4}}
{{^useSpringBoot4}}
{{#useSpringBoot3}}

kotlin {
Expand All @@ -128,6 +137,7 @@ kotlin {
}
}
{{/useSpringBoot3}}
{{/useSpringBoot4}}
{{/jvm-spring-webclient}}
{{#jvm-spring-restclient}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import com.fasterxml.jackson.annotation.JsonProperty
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.WebClientResponseException
{{#jackson}}
{{^useJackson3}}
import org.springframework.http.codec.json.Jackson2JsonDecoder
import org.springframework.http.codec.json.Jackson2JsonEncoder
{{/useJackson3}}
{{#useJackson3}}
import org.springframework.http.codec.json.JacksonJsonDecoder
import org.springframework.http.codec.json.JacksonJsonEncoder
{{/useJackson3}}
{{/jackson}}
import org.springframework.http.ResponseEntity
import org.springframework.http.MediaType
Expand All @@ -27,8 +33,14 @@ import {{packageName}}.infrastructure.*
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}constructor(baseUrl: String) : this(WebClient.builder()
.baseUrl(baseUrl)
.codecs {
{{^useJackson3}}
it.defaultCodecs().jackson2JsonEncoder(Jackson2JsonEncoder(Serializer.jacksonObjectMapper, MediaType.APPLICATION_JSON))
it.defaultCodecs().jackson2JsonDecoder(Jackson2JsonDecoder(Serializer.jacksonObjectMapper, MediaType.APPLICATION_JSON))
{{/useJackson3}}
{{#useJackson3}}
it.defaultCodecs().jacksonJsonEncoder(JacksonJsonEncoder(Serializer.jacksonObjectMapper, MediaType.APPLICATION_JSON))
it.defaultCodecs().jacksonJsonDecoder(JacksonJsonDecoder(Serializer.jacksonObjectMapper, MediaType.APPLICATION_JSON))
{{/useJackson3}}
}
.build()
)
Expand Down
Loading