Skip to content

Commit

Permalink
Bugfix Kotlin-client: Can now handle default dataclass values for mul…
Browse files Browse the repository at this point in the history
…tiplatform (#12242)
  • Loading branch information
sjoblomj authored Apr 26, 2022
1 parent 5de527e commit 074010e
Show file tree
Hide file tree
Showing 67 changed files with 2,511 additions and 4 deletions.
7 changes: 7 additions & 0 deletions bin/configs/kotlin-bigdecimal-default-multiplatform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
generatorName: kotlin
outputDir: samples/client/petstore/kotlin-bigdecimal-default-multiplatform
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10866_bigdecimal_default.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
artifactId: kotlin-bigdecimal-default-multiplatform
library: multiplatform
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
generatorName: kotlin
outputDir: samples/client/petstore/kotlin-bigdecimal-default
outputDir: samples/client/petstore/kotlin-bigdecimal-default-okhttp4
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_10866_bigdecimal_default.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
artifactId: kotlin-bigdecimal-default
artifactId: kotlin-bigdecimal-default-okhttp4
library: jvm-okhttp4
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
{{#deprecated}}
@Deprecated(message = "This property is deprecated.")
{{/deprecated}}
{{#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}}
{{#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}}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
{{#deprecated}}
@Deprecated(message = "This property is deprecated.")
{{/deprecated}}
{{#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}}
{{#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}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
README.md
build.gradle.kts
docs/Apa.md
docs/DefaultApi.md
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
gradlew
gradlew.bat
settings.gradle.kts
src/commonTest/kotlin/util/Coroutine.kt
src/iosTest/kotlin/util/Coroutine.kt
src/jsTest/kotlin/util/Coroutine.kt
src/jvmTest/kotlin/util/Coroutine.kt
src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt
src/main/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt
src/main/kotlin/org/openapitools/client/auth/Authentication.kt
src/main/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt
src/main/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt
src/main/kotlin/org/openapitools/client/auth/OAuth.kt
src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
src/main/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt
src/main/kotlin/org/openapitools/client/infrastructure/Bytes.kt
src/main/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt
src/main/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt
src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt
src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt
src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt
src/main/kotlin/org/openapitools/client/models/Apa.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# org.openapitools.client - Kotlin client library for Demo

## Requires

* Kotlin 1.5.10

## Build

```
./gradlew check assemble
```

This runs all tests and packages the library.

## Features/Implementation Notes

* Supports JSON inputs/outputs, File inputs, and Form inputs.
* Supports collection formats for query parameters: csv, tsv, ssv, pipes.
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.


<a name="documentation-for-api-endpoints"></a>
## Documentation for API Endpoints

All URIs are relative to *http://localhost*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*DefaultApi* | [**testPost**](docs/DefaultApi.md#testpost) | **POST** /test |


<a name="documentation-for-models"></a>
## Documentation for Models

- [org.openapitools.client.models.Apa](docs/Apa.md)


<a name="documentation-for-authorization"></a>
## Documentation for Authorization

All endpoints do not require authorization.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
kotlin("multiplatform") version "1.6.0" // kotlin_version
kotlin("plugin.serialization") version "1.6.0" // kotlin_version
}

group = "org.openapitools"
version = "1.0.0"

val kotlin_version = "1.6.0"
val coroutines_version = "1.5.2"
val serialization_version = "1.3.0"
val ktor_version = "1.6.4"

repositories {
mavenCentral()
}

kotlin {
jvm()
ios { binaries { framework { freeCompilerArgs += "-Xobjc-generics" } } }
js {
browser()
nodejs()
}

sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version")
api("io.ktor:ktor-client-core:$ktor_version")
api("io.ktor:ktor-client-json:$ktor_version")
api("io.ktor:ktor-client-serialization:$ktor_version")
}
}

val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation("io.ktor:ktor-client-mock:$ktor_version")
}
}

val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk7"))
implementation("io.ktor:ktor-client-cio-jvm:$ktor_version")
}
}

val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}

val iosMain by getting {
dependencies {
api("io.ktor:ktor-client-ios:$ktor_version")
}
}

val iosTest by getting

val jsMain by getting {
dependencies {
api("io.ktor:ktor-client-js:$ktor_version")
}
}

val jsTest by getting

all {
languageSettings.apply {
useExperimentalAnnotation("kotlin.Experimental")
}
}
}
}

tasks {
register("iosTest") {
val device = project.findProperty("device")?.toString() ?: "iPhone 8"
dependsOn("linkDebugTestIosX64")
group = JavaBasePlugin.VERIFICATION_GROUP
description = "Execute unit tests on ${device} simulator"
doLast {
val binary = kotlin.targets.getByName<KotlinNativeTarget>("iosX64").binaries.getTest("DEBUG")
exec {
commandLine("xcrun", "simctl", "spawn", device, binary.outputFile)
}
}
}
register("test") {
dependsOn("allTests")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Apa

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**bepa** | **kotlin.Double** | |
**cepa** | **kotlin.Double** | |
**depa** | **kotlin.Double** | | [optional]
**epa** | **kotlin.Double** | | [optional]
**fepa** | **kotlin.Double** | | [optional]
**gepa** | **kotlin.Double** | | [optional]



Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# DefaultApi

All URIs are relative to *http://localhost*

Method | HTTP request | Description
------------- | ------------- | -------------
[**testPost**](DefaultApi.md#testPost) | **POST** /test |


<a name="testPost"></a>
# **testPost**
> testPost(apa)


### Example
```kotlin
// Import classes:
//import org.openapitools.client.infrastructure.*
//import org.openapitools.client.models.*

val apiInstance = DefaultApi()
val apa : Apa = // Apa |
try {
apiInstance.testPost(apa)
} catch (e: ClientException) {
println("4xx response calling DefaultApi#testPost")
e.printStackTrace()
} catch (e: ServerException) {
println("5xx response calling DefaultApi#testPost")
e.printStackTrace()
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**apa** | [**Apa**](Apa.md)| |

### Return type

null (empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: Not defined

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 074010e

Please sign in to comment.