Skip to content
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

[Kotlin][Tests]: Add test for kotlin-jvm-okhttp #20338

Merged
merged 2 commits into from
Dec 17, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/samples-kotlin-echo-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
# clients
- samples/client/echo_api/kotlin-jvm-spring-3-restclient
- samples/client/echo_api/kotlin-model-prefix-type-mappings
- samples/client/echo_api/kotlin-jvm-okhttp
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ samples/client/petstore/kotlin*/src/main/kotlin/test/
samples/client/petstore/kotlin*/build/
samples/server/others/kotlin-server/jaxrs-spec/build/
samples/client/echo_api/kotlin-jvm-spring-3-restclient/build/
samples/client/echo_api/kotlin-jvm-okhttp/build/

# haskell
.stack-work
Expand Down
8 changes: 8 additions & 0 deletions bin/configs/kotlin-jvm-okhttp-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generatorName: kotlin
outputDir: samples/client/echo_api/kotlin-jvm-okhttp
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
modelNamePrefix: Api
additionalProperties:
library: jvm-okhttp4
artifactId: kotlin-jvm-okhttp-echo-api
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
54 changes: 54 additions & 0 deletions samples/client/echo_api/kotlin-jvm-okhttp/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
README.md
build.gradle
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
docs/Category.md
docs/DefaultValue.md
docs/FormApi.md
docs/HeaderApi.md
docs/NumberPropertiesOnly.md
docs/PathApi.md
docs/Pet.md
docs/Query.md
docs/QueryApi.md
docs/StringEnumRef.md
docs/Tag.md
docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
gradlew
gradlew.bat
settings.gradle
src/main/kotlin/org/openapitools/client/apis/AuthApi.kt
src/main/kotlin/org/openapitools/client/apis/BodyApi.kt
src/main/kotlin/org/openapitools/client/apis/FormApi.kt
src/main/kotlin/org/openapitools/client/apis/HeaderApi.kt
src/main/kotlin/org/openapitools/client/apis/PathApi.kt
src/main/kotlin/org/openapitools/client/apis/QueryApi.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/ApiBird.kt
src/main/kotlin/org/openapitools/client/models/ApiCategory.kt
src/main/kotlin/org/openapitools/client/models/ApiDefaultValue.kt
src/main/kotlin/org/openapitools/client/models/ApiNumberPropertiesOnly.kt
src/main/kotlin/org/openapitools/client/models/ApiPet.kt
src/main/kotlin/org/openapitools/client/models/ApiQuery.kt
src/main/kotlin/org/openapitools/client/models/ApiStringEnumRef.kt
src/main/kotlin/org/openapitools/client/models/ApiTag.kt
src/main/kotlin/org/openapitools/client/models/ApiTestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.11.0-SNAPSHOT
103 changes: 103 additions & 0 deletions samples/client/echo_api/kotlin-jvm-okhttp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# org.openapitools.client - Kotlin client library for Echo Server API

Echo Server API

## 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: 0.1.0
- Package version:
- Generator version: 7.11.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:3000*

| Class | Method | HTTP request | Description |
| ------------ | ------------- | ------------- | ------------- |
| *AuthApi* | [**testAuthHttpBasic**](docs/AuthApi.md#testauthhttpbasic) | **POST** /auth/http/basic | To test HTTP basic authentication |
| *AuthApi* | [**testAuthHttpBearer**](docs/AuthApi.md#testauthhttpbearer) | **POST** /auth/http/bearer | To test HTTP bearer authentication |
| *BodyApi* | [**testBinaryGif**](docs/BodyApi.md#testbinarygif) | **POST** /binary/gif | Test binary (gif) response body |
| *BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testbodyapplicationoctetstreambinary) | **POST** /body/application/octetstream/binary | Test body parameter(s) |
| *BodyApi* | [**testBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testbodymultipartformdataarrayofbinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime |
| *BodyApi* | [**testBodyMultipartFormdataSingleBinary**](docs/BodyApi.md#testbodymultipartformdatasinglebinary) | **POST** /body/application/octetstream/single_binary | Test single binary in multipart mime |
| *BodyApi* | [**testEchoBodyFreeFormObjectResponseString**](docs/BodyApi.md#testechobodyfreeformobjectresponsestring) | **POST** /echo/body/FreeFormObject/response_string | Test free form object |
| *BodyApi* | [**testEchoBodyPet**](docs/BodyApi.md#testechobodypet) | **POST** /echo/body/Pet | Test body parameter(s) |
| *BodyApi* | [**testEchoBodyPetResponseString**](docs/BodyApi.md#testechobodypetresponsestring) | **POST** /echo/body/Pet/response_string | Test empty response body |
| *BodyApi* | [**testEchoBodyTagResponseString**](docs/BodyApi.md#testechobodytagresponsestring) | **POST** /echo/body/Tag/response_string | Test empty json (request body) |
| *FormApi* | [**testFormIntegerBooleanString**](docs/FormApi.md#testformintegerbooleanstring) | **POST** /form/integer/boolean/string | Test form parameter(s) |
| *FormApi* | [**testFormOneof**](docs/FormApi.md#testformoneof) | **POST** /form/oneof | Test form parameter(s) for oneOf schema |
| *HeaderApi* | [**testHeaderIntegerBooleanStringEnums**](docs/HeaderApi.md#testheaderintegerbooleanstringenums) | **GET** /header/integer/boolean/string/enums | Test header parameter(s) |
| *PathApi* | [**testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath**](docs/PathApi.md#testspathstringpathstringintegerpathintegerenumnonrefstringpathenumrefstringpath) | **GET** /path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path} | Test path parameter(s) |
| *QueryApi* | [**testEnumRefString**](docs/QueryApi.md#testenumrefstring) | **GET** /query/enum_ref_string | Test query parameter(s) |
| *QueryApi* | [**testQueryDatetimeDateString**](docs/QueryApi.md#testquerydatetimedatestring) | **GET** /query/datetime/date/string | Test query parameter(s) |
| *QueryApi* | [**testQueryIntegerBooleanString**](docs/QueryApi.md#testqueryintegerbooleanstring) | **GET** /query/integer/boolean/string | Test query parameter(s) |
| *QueryApi* | [**testQueryStyleDeepObjectExplodeTrueObject**](docs/QueryApi.md#testquerystyledeepobjectexplodetrueobject) | **GET** /query/style_deepObject/explode_true/object | Test query parameter(s) |
| *QueryApi* | [**testQueryStyleFormExplodeTrueArrayString**](docs/QueryApi.md#testquerystyleformexplodetruearraystring) | **GET** /query/style_form/explode_true/array_string | Test query parameter(s) |
| *QueryApi* | [**testQueryStyleFormExplodeTrueObject**](docs/QueryApi.md#testquerystyleformexplodetrueobject) | **GET** /query/style_form/explode_true/object | Test query parameter(s) |


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

- [org.openapitools.client.models.ApiBird](docs/ApiBird.md)
- [org.openapitools.client.models.ApiCategory](docs/ApiCategory.md)
- [org.openapitools.client.models.ApiDefaultValue](docs/ApiDefaultValue.md)
- [org.openapitools.client.models.ApiNumberPropertiesOnly](docs/ApiNumberPropertiesOnly.md)
- [org.openapitools.client.models.ApiPet](docs/ApiPet.md)
- [org.openapitools.client.models.ApiQuery](docs/ApiQuery.md)
- [org.openapitools.client.models.ApiStringEnumRef](docs/ApiStringEnumRef.md)
- [org.openapitools.client.models.ApiTag](docs/ApiTag.md)
- [org.openapitools.client.models.ApiTestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter](docs/ApiTestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md)


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


Authentication schemes defined for the API:
<a id="http_auth"></a>
### http_auth

- **Type**: HTTP basic authentication

<a id="http_bearer_auth"></a>
### http_bearer_auth

- **Type**: HTTP Bearer Token authentication



## Author

[email protected]
62 changes: 62 additions & 0 deletions samples/client/echo_api/kotlin-jvm-okhttp/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"
}
101 changes: 101 additions & 0 deletions samples/client/echo_api/kotlin-jvm-okhttp/docs/AuthApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# AuthApi

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

| Method | HTTP request | Description |
| ------------- | ------------- | ------------- |
| [**testAuthHttpBasic**](AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication |
| [**testAuthHttpBearer**](AuthApi.md#testAuthHttpBearer) | **POST** /auth/http/bearer | To test HTTP bearer authentication |


<a id="testAuthHttpBasic"></a>
# **testAuthHttpBasic**
> kotlin.String testAuthHttpBasic()

To test HTTP basic authentication

To test HTTP basic authentication

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

val apiInstance = AuthApi()
try {
val result : kotlin.String = apiInstance.testAuthHttpBasic()
println(result)
} catch (e: ClientException) {
println("4xx response calling AuthApi#testAuthHttpBasic")
e.printStackTrace()
} catch (e: ServerException) {
println("5xx response calling AuthApi#testAuthHttpBasic")
e.printStackTrace()
}
```

### Parameters
This endpoint does not need any parameter.

### Return type

**kotlin.String**

### Authorization


Configure http_auth:
ApiClient.username = ""
ApiClient.password = ""

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: text/plain

<a id="testAuthHttpBearer"></a>
# **testAuthHttpBearer**
> kotlin.String testAuthHttpBearer()

To test HTTP bearer authentication

To test HTTP bearer authentication

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

val apiInstance = AuthApi()
try {
val result : kotlin.String = apiInstance.testAuthHttpBearer()
println(result)
} catch (e: ClientException) {
println("4xx response calling AuthApi#testAuthHttpBearer")
e.printStackTrace()
} catch (e: ServerException) {
println("5xx response calling AuthApi#testAuthHttpBearer")
e.printStackTrace()
}
```

### Parameters
This endpoint does not need any parameter.

### Return type

**kotlin.String**

### Authorization


Configure http_bearer_auth:
ApiClient.accessToken = ""

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: text/plain

11 changes: 11 additions & 0 deletions samples/client/echo_api/kotlin-jvm-okhttp/docs/Bird.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# ApiBird

## Properties
| Name | Type | Description | Notes |
| ------------ | ------------- | ------------- | ------------- |
| **propertySize** | **kotlin.String** | | [optional] |
| **color** | **kotlin.String** | | [optional] |



Loading
Loading