Skip to content

Commit 074010e

Browse files
authored
Bugfix Kotlin-client: Can now handle default dataclass values for multiplatform (OpenAPITools#12242)
1 parent 5de527e commit 074010e

File tree

67 files changed

+2511
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2511
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: kotlin
2+
outputDir: samples/client/petstore/kotlin-bigdecimal-default-multiplatform
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10866_bigdecimal_default.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
5+
additionalProperties:
6+
artifactId: kotlin-bigdecimal-default-multiplatform
7+
library: multiplatform
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
generatorName: kotlin
2-
outputDir: samples/client/petstore/kotlin-bigdecimal-default
2+
outputDir: samples/client/petstore/kotlin-bigdecimal-default-okhttp4
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10866_bigdecimal_default.yaml
44
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
55
additionalProperties:
6-
artifactId: kotlin-bigdecimal-default
6+
artifactId: kotlin-bigdecimal-default-okhttp4
7+
library: jvm-okhttp4

modules/openapi-generator/src/main/resources/kotlin-client/data_class_opt_var.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
{{#deprecated}}
1919
@Deprecated(message = "This property is deprecated.")
2020
{{/deprecated}}
21-
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isArray}}{{#isList}}{{#uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}Set{{/uniqueItems}}{{^uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}List{{/uniqueItems}}{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{^items.isEnum}}{{^items.isPrimitiveType}}{{^items.isModel}}{{#kotlinx_serialization}}@Contextual {{/kotlinx_serialization}}{{/items.isModel}}{{/items.isPrimitiveType}}{{{items.dataType}}}{{/items.isEnum}}{{#items.isEnum}}{{classname}}.{{{nameInCamelCase}}}{{/items.isEnum}}>{{/isArray}}{{^isEnum}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{classname}}.{{{nameInCamelCase}}}{{/isArray}}{{/isEnum}}? = {{^defaultValue}}null{{/defaultValue}}{{#defaultValue}}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
21+
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isArray}}{{#isList}}{{#uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}Set{{/uniqueItems}}{{^uniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}List{{/uniqueItems}}{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{^items.isEnum}}{{^items.isPrimitiveType}}{{^items.isModel}}{{#kotlinx_serialization}}@Contextual {{/kotlinx_serialization}}{{/items.isModel}}{{/items.isPrimitiveType}}{{{items.dataType}}}{{/items.isEnum}}{{#items.isEnum}}{{classname}}.{{{nameInCamelCase}}}{{/items.isEnum}}>{{/isArray}}{{^isEnum}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{classname}}.{{{nameInCamelCase}}}{{/isArray}}{{/isEnum}}? = {{^defaultValue}}null{{/defaultValue}}{{#defaultValue}}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{^multiplatform}}{{{dataType}}}("{{{defaultValue}}}"){{/multiplatform}}{{#multiplatform}}({{{defaultValue}}}).toDouble(){{/multiplatform}}{{/isNumber}}{{/defaultValue}}

modules/openapi-generator/src/main/resources/kotlin-client/data_class_req_var.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
{{#deprecated}}
1919
@Deprecated(message = "This property is deprecated.")
2020
{{/deprecated}}
21-
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isArray}}{{#isList}}{{#isUniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}Set{{/isUniqueItems}}{{^isUniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}List{{/isUniqueItems}}{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{^items.isEnum}}{{^items.isPrimitiveType}}{{^items.isModel}}{{#kotlinx_serialization}}@Contextual {{/kotlinx_serialization}}{{/items.isModel}}{{/items.isPrimitiveType}}{{{items.dataType}}}{{/items.isEnum}}{{#items.isEnum}}{{classname}}.{{{nameInCamelCase}}}{{/items.isEnum}}>{{/isArray}}{{^isEnum}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{classname}}.{{{nameInCamelCase}}}{{/isArray}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
21+
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isArray}}{{#isList}}{{#isUniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}Set{{/isUniqueItems}}{{^isUniqueItems}}kotlin.collections.{{#modelMutable}}Mutable{{/modelMutable}}List{{/isUniqueItems}}{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{^items.isEnum}}{{^items.isPrimitiveType}}{{^items.isModel}}{{#kotlinx_serialization}}@Contextual {{/kotlinx_serialization}}{{/items.isModel}}{{/items.isPrimitiveType}}{{{items.dataType}}}{{/items.isEnum}}{{#items.isEnum}}{{classname}}.{{{nameInCamelCase}}}{{/items.isEnum}}>{{/isArray}}{{^isEnum}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{classname}}.{{{nameInCamelCase}}}{{/isArray}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{^multiplatform}}{{{dataType}}}("{{{defaultValue}}}"){{/multiplatform}}{{#multiplatform}}({{{defaultValue}}}).toDouble(){{/multiplatform}}{{/isNumber}}{{/defaultValue}}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
README.md
2+
build.gradle.kts
3+
docs/Apa.md
4+
docs/DefaultApi.md
5+
gradle/wrapper/gradle-wrapper.jar
6+
gradle/wrapper/gradle-wrapper.properties
7+
gradlew
8+
gradlew.bat
9+
settings.gradle.kts
10+
src/commonTest/kotlin/util/Coroutine.kt
11+
src/iosTest/kotlin/util/Coroutine.kt
12+
src/jsTest/kotlin/util/Coroutine.kt
13+
src/jvmTest/kotlin/util/Coroutine.kt
14+
src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt
15+
src/main/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt
16+
src/main/kotlin/org/openapitools/client/auth/Authentication.kt
17+
src/main/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt
18+
src/main/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt
19+
src/main/kotlin/org/openapitools/client/auth/OAuth.kt
20+
src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt
21+
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
22+
src/main/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt
23+
src/main/kotlin/org/openapitools/client/infrastructure/Bytes.kt
24+
src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt
25+
src/main/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt
26+
src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt
27+
src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt
28+
src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt
29+
src/main/kotlin/org/openapitools/client/models/Apa.kt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.0.0-SNAPSHOT
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# org.openapitools.client - Kotlin client library for Demo
2+
3+
## Requires
4+
5+
* Kotlin 1.5.10
6+
7+
## Build
8+
9+
```
10+
./gradlew check assemble
11+
```
12+
13+
This runs all tests and packages the library.
14+
15+
## Features/Implementation Notes
16+
17+
* Supports JSON inputs/outputs, File inputs, and Form inputs.
18+
* Supports collection formats for query parameters: csv, tsv, ssv, pipes.
19+
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.
20+
21+
22+
<a name="documentation-for-api-endpoints"></a>
23+
## Documentation for API Endpoints
24+
25+
All URIs are relative to *http://localhost*
26+
27+
Class | Method | HTTP request | Description
28+
------------ | ------------- | ------------- | -------------
29+
*DefaultApi* | [**testPost**](docs/DefaultApi.md#testpost) | **POST** /test |
30+
31+
32+
<a name="documentation-for-models"></a>
33+
## Documentation for Models
34+
35+
- [org.openapitools.client.models.Apa](docs/Apa.md)
36+
37+
38+
<a name="documentation-for-authorization"></a>
39+
## Documentation for Authorization
40+
41+
All endpoints do not require authorization.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
2+
3+
plugins {
4+
kotlin("multiplatform") version "1.6.0" // kotlin_version
5+
kotlin("plugin.serialization") version "1.6.0" // kotlin_version
6+
}
7+
8+
group = "org.openapitools"
9+
version = "1.0.0"
10+
11+
val kotlin_version = "1.6.0"
12+
val coroutines_version = "1.5.2"
13+
val serialization_version = "1.3.0"
14+
val ktor_version = "1.6.4"
15+
16+
repositories {
17+
mavenCentral()
18+
}
19+
20+
kotlin {
21+
jvm()
22+
ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } }
23+
js {
24+
browser()
25+
nodejs()
26+
}
27+
28+
sourceSets {
29+
val commonMain by getting {
30+
dependencies {
31+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
32+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version")
33+
api("io.ktor:ktor-client-core:$ktor_version")
34+
api("io.ktor:ktor-client-json:$ktor_version")
35+
api("io.ktor:ktor-client-serialization:$ktor_version")
36+
}
37+
}
38+
39+
val commonTest by getting {
40+
dependencies {
41+
implementation(kotlin("test"))
42+
implementation("io.ktor:ktor-client-mock:$ktor_version")
43+
}
44+
}
45+
46+
val jvmMain by getting {
47+
dependencies {
48+
implementation(kotlin("stdlib-jdk7"))
49+
implementation("io.ktor:ktor-client-cio-jvm:$ktor_version")
50+
}
51+
}
52+
53+
val jvmTest by getting {
54+
dependencies {
55+
implementation(kotlin("test-junit"))
56+
}
57+
}
58+
59+
val iosMain by getting {
60+
dependencies {
61+
api("io.ktor:ktor-client-ios:$ktor_version")
62+
}
63+
}
64+
65+
val iosTest by getting
66+
67+
val jsMain by getting {
68+
dependencies {
69+
api("io.ktor:ktor-client-js:$ktor_version")
70+
}
71+
}
72+
73+
val jsTest by getting
74+
75+
all {
76+
languageSettings.apply {
77+
useExperimentalAnnotation("kotlin.Experimental")
78+
}
79+
}
80+
}
81+
}
82+
83+
tasks {
84+
register("iosTest") {
85+
val device = project.findProperty("device")?.toString() ?: "iPhone 8"
86+
dependsOn("linkDebugTestIosX64")
87+
group = JavaBasePlugin.VERIFICATION_GROUP
88+
description = "Execute unit tests on ${device} simulator"
89+
doLast {
90+
val binary = kotlin.targets.getByName<KotlinNativeTarget>("iosX64").binaries.getTest("DEBUG")
91+
exec {
92+
commandLine("xcrun", "simctl", "spawn", device, binary.outputFile)
93+
}
94+
}
95+
}
96+
register("test") {
97+
dependsOn("allTests")
98+
}
99+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# Apa
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**bepa** | **kotlin.Double** | |
8+
**cepa** | **kotlin.Double** | |
9+
**depa** | **kotlin.Double** | | [optional]
10+
**epa** | **kotlin.Double** | | [optional]
11+
**fepa** | **kotlin.Double** | | [optional]
12+
**gepa** | **kotlin.Double** | | [optional]
13+
14+
15+

0 commit comments

Comments
 (0)