-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[kotlin-client] Support for integer enums for multiplatform with custom serializer #23211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wing328
merged 4 commits into
master
from
rlnt-kotlin-client/integer-enums-multiplatform
Mar 12, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| generatorName: kotlin | ||
| outputDir: samples/client/petstore/kotlin-enum-integers-multiplatform | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_21204_enum_integers.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/kotlin-client | ||
| additionalProperties: | ||
| artifactId: kotlin-enum-integers-multiplatform | ||
| library: multiplatform | ||
| dateLibrary: kotlinx-datetime | ||
| sortParamsByRequiredFlag: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
modules/openapi-generator/src/test/resources/3_0/issue_21204_enum_integers.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: Demo | ||
| version: v1 | ||
|
|
||
| components: | ||
| schemas: | ||
| Code: | ||
| type: integer | ||
| enum: | ||
| - 0 | ||
| - 1 | ||
| - 2 | ||
|
|
||
| paths: | ||
| /do: | ||
| get: | ||
| summary: Do something | ||
| responses: | ||
| 200: | ||
| description: Successful response | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| required: | ||
| - code | ||
| properties: | ||
| code: | ||
| $ref: '#/components/schemas/Code' |
23 changes: 23 additions & 0 deletions
23
samples/client/petstore/kotlin-enum-integers-multiplatform/.openapi-generator-ignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
26 changes: 26 additions & 0 deletions
26
samples/client/petstore/kotlin-enum-integers-multiplatform/.openapi-generator/FILES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| README.md | ||
| build.gradle.kts | ||
| docs/Code.md | ||
| docs/DefaultApi.md | ||
| docs/DoGet200Response.md | ||
| gradle/wrapper/gradle-wrapper.jar | ||
| gradle/wrapper/gradle-wrapper.properties | ||
| gradlew | ||
| gradlew.bat | ||
| settings.gradle.kts | ||
| src/commonMain/kotlin/org/openapitools/client/apis/DefaultApi.kt | ||
| src/commonMain/kotlin/org/openapitools/client/auth/ApiKeyAuth.kt | ||
| src/commonMain/kotlin/org/openapitools/client/auth/Authentication.kt | ||
| src/commonMain/kotlin/org/openapitools/client/auth/HttpBasicAuth.kt | ||
| src/commonMain/kotlin/org/openapitools/client/auth/HttpBearerAuth.kt | ||
| src/commonMain/kotlin/org/openapitools/client/auth/OAuth.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/ApiClient.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/Base64ByteArray.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/HttpResponse.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/OctetByteArray.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/PartConfig.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt | ||
| src/commonMain/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt | ||
| src/commonMain/kotlin/org/openapitools/client/models/Code.kt | ||
| src/commonMain/kotlin/org/openapitools/client/models/DoGet200Response.kt |
1 change: 1 addition & 0 deletions
1
samples/client/petstore/kotlin-enum-integers-multiplatform/.openapi-generator/VERSION
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 7.21.0-SNAPSHOT |
53 changes: 53 additions & 0 deletions
53
samples/client/petstore/kotlin-enum-integers-multiplatform/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # org.openapitools.client - Kotlin client library for Demo | ||
|
|
||
| No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) | ||
|
|
||
| ## Overview | ||
| This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. | ||
|
|
||
| - API version: v1 | ||
| - Package version: | ||
| - Generator version: 7.21.0-SNAPSHOT | ||
| - Build package: org.openapitools.codegen.languages.KotlinClientCodegen | ||
|
|
||
| ## Requires | ||
|
|
||
| * Kotlin 2.2.20 | ||
|
|
||
| ## 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 id="documentation-for-api-endpoints"></a> | ||
| ## Documentation for API Endpoints | ||
|
|
||
| All URIs are relative to *http://localhost* | ||
|
|
||
| | Class | Method | HTTP request | Description | | ||
| | ------------ | ------------- | ------------- | ------------- | | ||
| | *DefaultApi* | [**doGet**](docs/DefaultApi.md#doget) | **GET** /do | Do something | | ||
|
|
||
|
|
||
| <a id="documentation-for-models"></a> | ||
| ## Documentation for Models | ||
|
|
||
| - [org.openapitools.client.models.Code](docs/Code.md) | ||
| - [org.openapitools.client.models.DoGet200Response](docs/DoGet200Response.md) | ||
|
|
||
|
|
||
| <a id="documentation-for-authorization"></a> | ||
| ## Documentation for Authorization | ||
|
|
||
| Endpoints do not require authorization. | ||
|
|
97 changes: 97 additions & 0 deletions
97
samples/client/petstore/kotlin-enum-integers-multiplatform/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
|
|
||
| plugins { | ||
| kotlin("multiplatform") version "2.2.20" // kotlin_version | ||
| kotlin("plugin.serialization") version "2.2.20" // kotlin_version | ||
| } | ||
|
|
||
| group = "org.openapitools" | ||
| version = "1.0.0" | ||
|
|
||
| val kotlin_version = "2.2.20" | ||
| val coroutines_version = "1.10.2" | ||
| val serialization_version = "1.9.0" | ||
| val ktor_version = "3.2.3" | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| kotlin { | ||
| jvm() | ||
| iosX64() | ||
| iosArm64() | ||
| iosSimulatorArm64() | ||
| js { | ||
| browser() | ||
| nodejs() | ||
| } | ||
|
|
||
| sourceSets { | ||
| commonMain { | ||
| 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-serialization:$ktor_version") | ||
| api("io.ktor:ktor-client-content-negotiation:$ktor_version") | ||
| api("io.ktor:ktor-serialization-kotlinx-json:$ktor_version") | ||
|
|
||
| api("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1") | ||
| } | ||
| } | ||
|
|
||
| commonTest { | ||
| dependencies { | ||
| implementation(kotlin("test")) | ||
| implementation("io.ktor:ktor-client-mock:$ktor_version") | ||
| } | ||
| } | ||
|
|
||
| jvmMain { | ||
| dependencies { | ||
| implementation(kotlin("stdlib-jdk7")) | ||
| implementation("io.ktor:ktor-client-cio-jvm:$ktor_version") | ||
| } | ||
| } | ||
|
|
||
| jvmTest { | ||
| dependencies { | ||
| implementation(kotlin("test-junit")) | ||
| } | ||
| } | ||
|
|
||
| iosMain { | ||
| dependencies { | ||
| api("io.ktor:ktor-client-ios:$ktor_version") | ||
| } | ||
| } | ||
|
|
||
| jsMain { | ||
| dependencies { | ||
| api("io.ktor:ktor-client-js:$ktor_version") | ||
| } | ||
| } | ||
|
|
||
| all { | ||
| languageSettings { | ||
| optIn("kotlin.time.ExperimentalTime") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks { | ||
| register<Exec>("iosTest") { | ||
| val device = project.findProperty("device")?.toString() ?: "iPhone 8" | ||
| dependsOn("linkDebugTestIosX64") | ||
| group = JavaBasePlugin.VERIFICATION_GROUP | ||
| description = "Execute unit tests on ${device} simulator" | ||
| val binary = kotlin.targets.getByName<KotlinNativeTarget>("iosX64").binaries.getTest("DEBUG") | ||
| commandLine("xcrun", "simctl", "spawn", device, binary.outputFile) | ||
| } | ||
| register("test") { | ||
| dependsOn("allTests") | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
samples/client/petstore/kotlin-enum-integers-multiplatform/docs/Code.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
| # Code | ||
|
|
||
| ## Enum | ||
|
|
||
|
|
||
| * `_0` (value: `0`) | ||
|
|
||
| * `_1` (value: `1`) | ||
|
|
||
| * `_2` (value: `2`) | ||
|
|
||
|
|
||
|
|
50 changes: 50 additions & 0 deletions
50
samples/client/petstore/kotlin-enum-integers-multiplatform/docs/DefaultApi.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # DefaultApi | ||
|
|
||
| All URIs are relative to *http://localhost* | ||
|
|
||
| | Method | HTTP request | Description | | ||
| | ------------- | ------------- | ------------- | | ||
| | [**doGet**](DefaultApi.md#doGet) | **GET** /do | Do something | | ||
|
|
||
|
|
||
| <a id="doGet"></a> | ||
| # **doGet** | ||
| > DoGet200Response doGet() | ||
|
|
||
| Do something | ||
|
|
||
| ### Example | ||
| ```kotlin | ||
| // Import classes: | ||
| //import org.openapitools.client.infrastructure.* | ||
| //import org.openapitools.client.models.* | ||
|
|
||
| val apiInstance = DefaultApi() | ||
| try { | ||
| val result : DoGet200Response = apiInstance.doGet() | ||
| println(result) | ||
| } catch (e: ClientException) { | ||
| println("4xx response calling DefaultApi#doGet") | ||
| e.printStackTrace() | ||
| } catch (e: ServerException) { | ||
| println("5xx response calling DefaultApi#doGet") | ||
| e.printStackTrace() | ||
| } | ||
| ``` | ||
|
|
||
| ### Parameters | ||
| This endpoint does not need any parameter. | ||
|
|
||
| ### Return type | ||
|
|
||
| [**DoGet200Response**](DoGet200Response.md) | ||
|
|
||
| ### Authorization | ||
|
|
||
| No authorization required | ||
|
|
||
| ### HTTP request headers | ||
|
|
||
| - **Content-Type**: Not defined | ||
| - **Accept**: application/json | ||
|
|
10 changes: 10 additions & 0 deletions
10
...les/client/petstore/kotlin-enum-integers-multiplatform/docs/DoGet200Response.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| # DoGet200Response | ||
|
|
||
| ## Properties | ||
| | Name | Type | Description | Notes | | ||
| | ------------ | ------------- | ------------- | ------------- | | ||
| | **code** | [**Code**](Code.md) | | | | ||
|
|
||
|
|
||
|
|
Binary file added
BIN
+42.5 KB
samples/client/petstore/kotlin-enum-integers-multiplatform/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
...ient/petstore/kotlin-enum-integers-multiplatform/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip | ||
| networkTimeout=10000 | ||
| validateDistributionUrl=true | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Use
entriesinstead ofvalues()in enum deserialization to avoid per-call array allocation.Prompt for AI agents