Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/samples-kotlin-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- 'samples/client/petstore/kotlin*/**'
- 'samples/client/others/kotlin-jvm-okhttp-parameter-tests/**'
- samples/client/others/kotlin-integer-enum/**
pull_request:
paths:
- 'samples/client/petstore/kotlin*/**'
- 'samples/client/others/kotlin-jvm-okhttp-parameter-tests/**'
- samples/client/others/kotlin-integer-enum/**

jobs:
build:
Expand Down Expand Up @@ -66,6 +68,7 @@ jobs:
- samples/client/petstore/kotlin-name-parameter-mappings
- samples/client/others/kotlin-jvm-okhttp-parameter-tests
- samples/client/others/kotlin-jvm-okhttp-path-comments
- samples/client/others/kotlin-integer-enum
- samples/client/petstore/kotlin-allOff-discriminator-kotlinx-serialization
steps:
- uses: actions/checkout@v5
Expand Down
6 changes: 6 additions & 0 deletions bin/configs/kotlin-integer-enum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: kotlin
outputDir: samples/client/others/kotlin-integer-enum
inputSpec: modules/openapi-generator/src/test/resources/3_0/pr_21746.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
artifactId: kotlin-integer-enum
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ import kotlinx.serialization.Serializable
{{#enumUnknownDefaultCase}}
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
{{^isString}}
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
{{/isString}}
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
{{/enumUnknownDefaultCase}}
{{^enumUnknownDefaultCase}}{{^isString}}
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
{{/isString}}{{/enumUnknownDefaultCase}}
{{/kotlinx_serialization}}
{{/multiplatform}}
{{#multiplatform}}
Expand All @@ -33,7 +46,7 @@ import kotlinx.serialization.*
*
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
*/
{{#multiplatform}}@Serializable{{/multiplatform}}{{#kotlinx_serialization}}@Serializable{{#enumUnknownDefaultCase}}(with = {{classname}}Serializer::class){{/enumUnknownDefaultCase}}{{/kotlinx_serialization}}
{{#multiplatform}}@Serializable{{/multiplatform}}{{#kotlinx_serialization}}@Serializable{{#enumUnknownDefaultCase}}(with = {{classname}}Serializer::class){{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}{{^isString}}(with = {{classname}}Serializer::class){{/isString}}{{/enumUnknownDefaultCase}}{{/kotlinx_serialization}}
{{^multiplatform}}
{{#moshi}}
@JsonClass(generateAdapter = false)
Expand All @@ -52,7 +65,9 @@ import kotlinx.serialization.*
@JsonProperty(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}){{#enumUnknownDefaultCase}}{{#-last}} @JsonEnumDefaultValue{{/-last}}{{/enumUnknownDefaultCase}}
{{/jackson}}
{{#kotlinx_serialization}}
{{#isString}}
@SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}})
{{/isString}}
{{/kotlinx_serialization}}
{{/multiplatform}}
{{#multiplatform}}
Expand Down Expand Up @@ -95,18 +110,40 @@ import kotlinx.serialization.*
}
}
}
}{{#kotlinx_serialization}}{{#enumUnknownDefaultCase}}

}
{{#kotlinx_serialization}}{{#enumUnknownDefaultCase}}
internal object {{classname}}Serializer : KSerializer<{{classname}}> {
override val descriptor = {{{dataType}}}.serializer().descriptor
override val descriptor = {{dataType}}.serializer().descriptor

override fun deserialize(decoder: Decoder): {{classname}} {
val value = decoder.decodeSerializableValue({{{dataType}}}.serializer())
return {{classname}}.values().firstOrNull { it.value == value }
{{#isString}}
?: {{classname}}.{{#allowableValues}}{{#enumVars}}{{#-last}}{{&name}}{{/-last}}{{/enumVars}}{{/allowableValues}}
{{/isString}}
{{^isString}}
?: throw IllegalArgumentException("Unknown enum value: $value")
{{/isString}}
}

override fun serialize(encoder: Encoder, value: {{classname}}) {
encoder.encodeSerializableValue({{{dataType}}}.serializer(), value.value)
}
}
{{/enumUnknownDefaultCase}}
{{^enumUnknownDefaultCase}}{{^isString}}
internal object {{classname}}Serializer : KSerializer<{{classname}}> {
override val descriptor = {{dataType}}.serializer().descriptor

override fun deserialize(decoder: Decoder): {{classname}} {
val value = decoder.decodeSerializableValue({{{dataType}}}.serializer())
return {{classname}}.values().firstOrNull { it.value == value }
?: throw IllegalArgumentException("Unknown enum value: $value")
}

override fun serialize(encoder: Encoder, value: {{classname}}) {
encoder.encodeSerializableValue({{{dataType}}}.serializer(), value.value)
}
}{{/enumUnknownDefaultCase}}{{/kotlinx_serialization}}
}
{{/isString}}{{/enumUnknownDefaultCase}}
{{/kotlinx_serialization}}
34 changes: 34 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/pr_21746.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.3
info:
title: Demo
version: v1

components:
schemas:
Code:
type: integer
enum:
- 0
- 1
StringCode:
type: string
enum:
- hello
- world

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'
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
32 changes: 32 additions & 0 deletions samples/client/others/kotlin-integer-enum/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
README.md
build.gradle
docs/Code.md
docs/DefaultApi.md
docs/DoGet200Response.md
docs/StringCode.md
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
gradlew
gradlew.bat
settings.gradle
src/main/kotlin/org/openapitools/client/apis/DefaultApi.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/ApiResponse.kt
src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.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/infrastructure/ResponseExtensions.kt
src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt
src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt
src/main/kotlin/org/openapitools/client/models/Code.kt
src/main/kotlin/org/openapitools/client/models/DoGet200Response.kt
src/main/kotlin/org/openapitools/client/models/StringCode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.15.0-SNAPSHOT
63 changes: 63 additions & 0 deletions samples/client/others/kotlin-integer-enum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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.15.0-SNAPSHOT
- Build package: org.openapitools.codegen.languages.KotlinClientCodegen

## Requires

* Kotlin 1.7.21
* Gradle 7.5

## Build

First, create the gradle wrapper script:

```
gradle wrapper
```

Then, run:

```
./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.
* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets.

<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)
- [org.openapitools.client.models.StringCode](docs/StringCode.md)


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

Endpoints do not require authorization.

62 changes: 62 additions & 0 deletions samples/client/others/kotlin-integer-enum/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
group 'org.openapitools'
version '1.0.0'

wrapper {
gradleVersion = '8.7'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}

buildscript {
ext.kotlin_version = '1.9.23'
ext.spotless_version = "6.25.0"

repositories {
maven { url "https://repo1.maven.org/maven2" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version"
}
}

apply plugin: 'kotlin'
apply plugin: 'maven-publish'
apply plugin: 'com.diffplug.spotless'

repositories {
maven { url "https://repo1.maven.org/maven2" }
}

// Use spotless plugin to automatically format code, remove unused import, etc
// To apply changes directly to the file, run `gradlew spotlessApply`
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
spotless {
// comment out below to run spotless as part of the `check` task
enforceCheck false

format 'misc', {
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
target '.gitignore'

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces() // Takes an integer argument if you don't like 4
endWithNewline()
}
kotlin {
ktfmt()
}
}

test {
useJUnitPlatform()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "com.squareup.moshi:moshi-kotlin:1.15.1"
implementation "com.squareup.moshi:moshi-adapters:1.15.1"
implementation "com.squareup.okhttp3:okhttp:4.12.0"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
}
12 changes: 12 additions & 0 deletions samples/client/others/kotlin-integer-enum/docs/Code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# Code

## Enum


* `_0` (value: `0`)

* `_1` (value: `1`)



Loading
Loading