Skip to content

Commit fac233b

Browse files
authored
[kotlin][client] add support for coroutines with OkHttp (#6362)
* [kotlin][client] add support for coroutines with OkHttp * [kotlin] fix petstore project
1 parent 0a5b02e commit fac233b

Some content is hidden

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

41 files changed

+3081
-2
lines changed

bin/kotlin-client-all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
./bin/kotlin-client-nullable.sh
1313
./bin/kotlin-client-retrofit2.sh
1414
./bin/kotlin-client-json-request-string.sh
15+
./bin/kotlin-client-petstore-okhttp-coroutines.sh
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
echo "# START SCRIPT: $SCRIPT"
5+
6+
while [ -h "$SCRIPT" ] ; do
7+
ls=$(ls -ld "$SCRIPT")
8+
link=$(expr "$ls" : '.*-> \(.*\)$')
9+
if expr "$link" : '/.*' > /dev/null; then
10+
SCRIPT="$link"
11+
else
12+
SCRIPT=$(dirname "$SCRIPT")/"$link"
13+
fi
14+
done
15+
16+
if [ ! -d "${APP_DIR}" ]; then
17+
APP_DIR=$(dirname "$SCRIPT")/..
18+
APP_DIR=$(cd "${APP_DIR}"; pwd)
19+
fi
20+
21+
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
22+
23+
if [ ! -f "$executable" ]
24+
then
25+
mvn clean package
26+
fi
27+
28+
samplePath="samples/client/petstore/kotlin-jvm-okhttp4-coroutines"
29+
30+
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
31+
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-client -g kotlin --artifact-id kotlin-petstore-okhttp4-coroutines-client --library jvm-okhttp4 --additional-properties serializationLibrary=gson,dateLibrary=java8,serializableModel=true,useCoroutines=true -o $samplePath $@"
32+
33+
echo "Cleaning previously generated files if any from $samplePath"
34+
rm -rf $samplePath
35+
36+
echo "Generating Kotling client..."
37+
java $JAVA_OPTS -jar $executable $ags

bin/openapi3/kotlin-client-petstore-all.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
./bin/openapi3/kotlin-client-petstore-retrofit2-coroutines.sh
88
./bin/openapi3/kotlin-client-petstore-retrofit2-rx.sh
99
./bin/openapi3/kotlin-client-petstore-retrofit2-rx2.sh
10-

modules/openapi-generator/src/main/resources/kotlin-client/api.mustache renamed to modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {{packageName}}.infrastructure.toMultiValue
4040
{{#isDeprecated}}
4141
@Deprecated(message = "This operation is deprecated.")
4242
{{/isDeprecated}}
43-
fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}} {
43+
{{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : {{#returnType}}{{{returnType}}}{{#nullableReturnType}}?{{/nullableReturnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}} {
4444
val localVariableBody: kotlin.Any? = {{#hasBodyParam}}{{#bodyParams}}{{{paramName}}}{{/bodyParams}}{{/hasBodyParam}}{{^hasBodyParam}}{{^hasFormParams}}null{{/hasFormParams}}{{#hasFormParams}}mapOf({{#formParams}}"{{{baseName}}}" to {{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/formParams}}){{/hasFormParams}}{{/hasBodyParam}}
4545
val localVariableQuery: MultiValueMap = {{^hasQueryParams}}mutableMapOf()
4646
{{/hasQueryParams}}{{#hasQueryParams}}mutableMapOf<kotlin.String, List<kotlin.String>>()
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.0.0-SNAPSHOT
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# org.openapitools.client - Kotlin client library for OpenAPI Petstore
2+
3+
## Requires
4+
5+
* Kotlin 1.3.41
6+
* Gradle 4.9
7+
8+
## Build
9+
10+
First, create the gradle wrapper script:
11+
12+
```
13+
gradle wrapper
14+
```
15+
16+
Then, run:
17+
18+
```
19+
./gradlew check assemble
20+
```
21+
22+
This runs all tests and packages the library.
23+
24+
## Features/Implementation Notes
25+
26+
* Supports JSON inputs/outputs, File inputs, and Form inputs.
27+
* Supports collection formats for query parameters: csv, tsv, ssv, pipes.
28+
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.
29+
* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets.
30+
31+
<a name="documentation-for-api-endpoints"></a>
32+
## Documentation for API Endpoints
33+
34+
All URIs are relative to *http://petstore.swagger.io/v2*
35+
36+
Class | Method | HTTP request | Description
37+
------------ | ------------- | ------------- | -------------
38+
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
39+
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
40+
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
41+
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
42+
*PetApi* | [**getPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
43+
*PetApi* | [**updatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
44+
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
45+
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
46+
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
47+
*StoreApi* | [**getInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
48+
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
49+
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
50+
*UserApi* | [**createUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
51+
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
52+
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
53+
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
54+
*UserApi* | [**getUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
55+
*UserApi* | [**loginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
56+
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
57+
*UserApi* | [**updateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
58+
59+
60+
<a name="documentation-for-models"></a>
61+
## Documentation for Models
62+
63+
- [org.openapitools.client.models.ApiResponse](docs/ApiResponse.md)
64+
- [org.openapitools.client.models.Category](docs/Category.md)
65+
- [org.openapitools.client.models.Order](docs/Order.md)
66+
- [org.openapitools.client.models.Pet](docs/Pet.md)
67+
- [org.openapitools.client.models.Tag](docs/Tag.md)
68+
- [org.openapitools.client.models.User](docs/User.md)
69+
70+
71+
<a name="documentation-for-authorization"></a>
72+
## Documentation for Authorization
73+
74+
<a name="api_key"></a>
75+
### api_key
76+
77+
- **Type**: API key
78+
- **API key parameter name**: api_key
79+
- **Location**: HTTP header
80+
81+
<a name="petstore_auth"></a>
82+
### petstore_auth
83+
84+
- **Type**: OAuth
85+
- **Flow**: implicit
86+
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
87+
- **Scopes**:
88+
- write:pets: modify pets in your account
89+
- read:pets: read your pets
90+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
group 'org.openapitools'
2+
version '1.0.0'
3+
4+
wrapper {
5+
gradleVersion = '4.9'
6+
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
7+
}
8+
9+
buildscript {
10+
ext.kotlin_version = '1.3.61'
11+
12+
repositories {
13+
maven { url "https://repo1.maven.org/maven2" }
14+
}
15+
dependencies {
16+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17+
}
18+
}
19+
20+
apply plugin: 'kotlin'
21+
22+
repositories {
23+
maven { url "https://repo1.maven.org/maven2" }
24+
}
25+
26+
test {
27+
useJUnitPlatform()
28+
}
29+
30+
dependencies {
31+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
32+
compile "com.google.code.gson:gson:2.8.6"
33+
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
34+
compile "com.squareup.okhttp3:okhttp:4.2.2"
35+
testCompile "io.kotlintest:kotlintest-runner-junit5:3.1.0"
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# ApiResponse
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**code** | **kotlin.Int** | | [optional]
8+
**type** | **kotlin.String** | | [optional]
9+
**message** | **kotlin.String** | | [optional]
10+
11+
12+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# Category
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**id** | **kotlin.Long** | | [optional]
8+
**name** | **kotlin.String** | | [optional]
9+
10+
11+

0 commit comments

Comments
 (0)