Skip to content

Commit 05de629

Browse files
committed
Add unit cases for issue 4062
1 parent 04a4d7a commit 05de629

File tree

24 files changed

+752
-0
lines changed

24 files changed

+752
-0
lines changed

bin/kotlin-uppercase-enum.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 -B clean package
26+
fi
27+
28+
# if you've executed sbt assembly previously it will use that instead.
29+
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
30+
ags="generate -t modules/openapi-generator/src/main/resources/kotlin-client -i modules/openapi-generator/src/test/resources/3_0/issue-4062.yaml -g kotlin --artifact-id kotlin-uppercase-enum --additional-properties enumPropertyNaming=UPPERCASE -o samples/client/petstore/kotlin-uppercase-enum $@"
31+
32+
java ${JAVA_OPTS} -jar ${executable} ${ags}
33+
34+
cp CI/samples.ci/client/petstore/kotlin-uppercase-enum/pom.xml samples/client/petstore/kotlin-uppercase-enum/pom.xml
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: Test for issue 4062
6+
version: 1.0.0
7+
title: OpenAPI Petstore
8+
license:
9+
name: Apache-2.0
10+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
11+
paths:
12+
/enum:
13+
get:
14+
tags:
15+
- enum
16+
summary: Get enums
17+
description: ''
18+
operationId: getEnum
19+
responses:
20+
'200':
21+
description: success
22+
content:
23+
application/json:
24+
schema:
25+
$ref: '#/components/schemas/PetEnum'
26+
components:
27+
schemas:
28+
PetEnum:
29+
type: string
30+
description: An enum with complex-ish naming
31+
enum:
32+
- myFirstValue
33+
- MY_SECOND_VALUE
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+
4.2.0-SNAPSHOT
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
*EnumApi* | [**getEnum**](docs/EnumApi.md#getenum) | **GET** /enum | Get enums
39+
40+
41+
<a name="documentation-for-models"></a>
42+
## Documentation for Models
43+
44+
- [org.openapitools.client.models.PetEnum](docs/PetEnum.md)
45+
46+
47+
<a name="documentation-for-authorization"></a>
48+
## Documentation for Authorization
49+
50+
All endpoints do not require authorization.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.41'
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
dependencies {
16+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17+
}
18+
}
19+
20+
apply plugin: 'kotlin'
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
26+
test {
27+
useJUnitPlatform()
28+
}
29+
30+
dependencies {
31+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
32+
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
33+
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
34+
compile "com.squareup.moshi:moshi-adapters:1.8.0"
35+
compile "com.squareup.okhttp3:okhttp:4.0.1"
36+
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
37+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# EnumApi
2+
3+
All URIs are relative to *http://petstore.swagger.io/v2*
4+
5+
Method | HTTP request | Description
6+
------------- | ------------- | -------------
7+
[**getEnum**](EnumApi.md#getEnum) | **GET** /enum | Get enums
8+
9+
10+
<a name="getEnum"></a>
11+
# **getEnum**
12+
> PetEnum getEnum()
13+
14+
Get enums
15+
16+
### Example
17+
```kotlin
18+
// Import classes:
19+
//import org.openapitools.client.infrastructure.*
20+
//import org.openapitools.client.models.*
21+
22+
val apiInstance = EnumApi()
23+
try {
24+
val result : PetEnum = apiInstance.getEnum()
25+
println(result)
26+
} catch (e: ClientException) {
27+
println("4xx response calling EnumApi#getEnum")
28+
e.printStackTrace()
29+
} catch (e: ServerException) {
30+
println("5xx response calling EnumApi#getEnum")
31+
e.printStackTrace()
32+
}
33+
```
34+
35+
### Parameters
36+
This endpoint does not need any parameter.
37+
38+
### Return type
39+
40+
[**PetEnum**](PetEnum.md)
41+
42+
### Authorization
43+
44+
No authorization required
45+
46+
### HTTP request headers
47+
48+
- **Content-Type**: Not defined
49+
- **Accept**: application/json
50+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# PetEnum
3+
4+
## Enum
5+
6+
7+
* `MY_FIRST_VALUE` (value: `"myFirstValue"`)
8+
9+
* `MY_SECOND_VALUE` (value: `"MY_SECOND_VALUE"`)
10+
11+
12+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
rootProject.name = 'kotlin-uppercase-enum'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* OpenAPI Petstore
3+
* Test for issue 4062
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
package org.openapitools.client.apis
13+
14+
import org.openapitools.client.models.PetEnum
15+
16+
import org.openapitools.client.infrastructure.ApiClient
17+
import org.openapitools.client.infrastructure.ClientException
18+
import org.openapitools.client.infrastructure.ClientError
19+
import org.openapitools.client.infrastructure.ServerException
20+
import org.openapitools.client.infrastructure.ServerError
21+
import org.openapitools.client.infrastructure.MultiValueMap
22+
import org.openapitools.client.infrastructure.RequestConfig
23+
import org.openapitools.client.infrastructure.RequestMethod
24+
import org.openapitools.client.infrastructure.ResponseType
25+
import org.openapitools.client.infrastructure.Success
26+
import org.openapitools.client.infrastructure.toMultiValue
27+
28+
class EnumApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiClient(basePath) {
29+
30+
/**
31+
* Get enums
32+
*
33+
* @return PetEnum
34+
*/
35+
@Suppress("UNCHECKED_CAST")
36+
fun getEnum() : PetEnum {
37+
val localVariableBody: kotlin.Any? = null
38+
val localVariableQuery: MultiValueMap = mapOf()
39+
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
40+
val localVariableConfig = RequestConfig(
41+
RequestMethod.GET,
42+
"/enum",
43+
query = localVariableQuery,
44+
headers = localVariableHeaders
45+
)
46+
val response = request<PetEnum>(
47+
localVariableConfig,
48+
localVariableBody
49+
)
50+
51+
return when (response.responseType) {
52+
ResponseType.Success -> (response as Success<*>).data as PetEnum
53+
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
54+
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
55+
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
56+
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
57+
}
58+
}
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.openapitools.client.infrastructure
2+
3+
typealias MultiValueMap = Map<String,List<String>>
4+
5+
fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
6+
"csv" -> ","
7+
"tsv" -> "\t"
8+
"pipes" -> "|"
9+
"ssv" -> " "
10+
else -> ""
11+
}
12+
13+
val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" }
14+
15+
fun <T : Any?> toMultiValue(items: Array<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter)
16+
= toMultiValue(items.asIterable(), collectionFormat, map)
17+
18+
fun <T : Any?> toMultiValue(items: Iterable<T>, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List<String> {
19+
return when(collectionFormat) {
20+
"multi" -> items.map(map)
21+
else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map))
22+
}
23+
}

0 commit comments

Comments
 (0)