forked from loafle/openapi-generator-original
fix kotlin client uppercase enum script
This commit is contained in:
parent
54cfab84b6
commit
3100f8c4e4
@ -31,4 +31,4 @@ ags="generate -t modules/openapi-generator/src/main/resources/kotlin-client -i m
|
||||
|
||||
java ${JAVA_OPTS} -jar ${executable} ${ags}
|
||||
|
||||
cp CI/samples.ci/client/petstore/kotlin-uppercase-enum/pom.xml samples/client/petstore/kotlin-uppercase-enum/pom.xml
|
||||
#cp CI/samples.ci/client/petstore/kotlin-uppercase-enum/pom.xml samples/client/petstore/kotlin-uppercase-enum/pom.xml
|
@ -1 +1 @@
|
||||
4.2.0-SNAPSHOT
|
||||
4.2.3-SNAPSHOT
|
@ -7,7 +7,7 @@ wrapper {
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.41'
|
||||
ext.kotlin_version = '1.3.61'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -30,8 +30,8 @@ test {
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
|
||||
compile "com.squareup.moshi:moshi-adapters:1.8.0"
|
||||
compile "com.squareup.okhttp3:okhttp:4.0.1"
|
||||
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.1.0"
|
||||
compile "com.squareup.moshi:moshi-kotlin:1.9.2"
|
||||
compile "com.squareup.moshi:moshi-adapters:1.9.2"
|
||||
compile "com.squareup.okhttp3:okhttp:4.2.2"
|
||||
testCompile "io.kotlintest:kotlintest-runner-junit5:3.1.0"
|
||||
}
|
||||
|
@ -31,11 +31,15 @@ class EnumApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
|
||||
* Get enums
|
||||
*
|
||||
* @return PetEnum
|
||||
* @throws UnsupportedOperationException If the API returns an informational or redirection response
|
||||
* @throws ClientException If the API returns a client error response
|
||||
* @throws ServerException If the API returns a server error response
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
|
||||
fun getEnum() : PetEnum {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
val localVariableQuery: MultiValueMap = mapOf()
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
val localVariableConfig = RequestConfig(
|
||||
RequestMethod.GET,
|
||||
@ -43,17 +47,23 @@ class EnumApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders
|
||||
)
|
||||
val response = request<PetEnum>(
|
||||
val localVarResponse = request<PetEnum>(
|
||||
localVariableConfig,
|
||||
localVariableBody
|
||||
)
|
||||
|
||||
return when (response.responseType) {
|
||||
ResponseType.Success -> (response as Success<*>).data as PetEnum
|
||||
return when (localVarResponse.responseType) {
|
||||
ResponseType.Success -> (localVarResponse as Success<*>).data as PetEnum
|
||||
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
||||
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
||||
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
|
||||
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
|
||||
ResponseType.ClientError -> {
|
||||
val localVarError = localVarResponse as ClientError<*>
|
||||
throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode)
|
||||
}
|
||||
ResponseType.ServerError -> {
|
||||
val localVarError = localVarResponse as ServerError<*>
|
||||
throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
typealias MultiValueMap = Map<String,List<String>>
|
||||
typealias MultiValueMap = MutableMap<String,List<String>>
|
||||
|
||||
fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) {
|
||||
"csv" -> ","
|
||||
"tsv" -> "\t"
|
||||
"pipes" -> "|"
|
||||
"ssv" -> " "
|
||||
"pipe" -> "|"
|
||||
"space" -> " "
|
||||
else -> ""
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
@ -107,7 +108,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete()
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(body, contentType))
|
||||
RequestMethod.GET -> Request.Builder().url(url)
|
||||
RequestMethod.HEAD -> Request.Builder().url(url).head()
|
||||
RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(body, contentType))
|
||||
@ -150,4 +151,8 @@ open class ApiClient(val baseUrl: String) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||
return value.toString()
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,4 @@ class ByteArrayAdapter {
|
||||
|
||||
@FromJson
|
||||
fun fromJson(data: String): ByteArray = data.toByteArray()
|
||||
}
|
||||
}
|
||||
|
@ -3,38 +3,14 @@ package org.openapitools.client.infrastructure
|
||||
|
||||
import java.lang.RuntimeException
|
||||
|
||||
open class ClientException : RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs an [ClientException] with no detail message.
|
||||
*/
|
||||
constructor() : super()
|
||||
|
||||
/**
|
||||
* Constructs an [ClientException] with the specified detail message.
|
||||
|
||||
* @param message the detail message.
|
||||
*/
|
||||
constructor(message: kotlin.String) : super(message)
|
||||
open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 123L
|
||||
}
|
||||
}
|
||||
|
||||
open class ServerException : RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs an [ServerException] with no detail message.
|
||||
*/
|
||||
constructor() : super()
|
||||
|
||||
/**
|
||||
* Constructs an [ServerException] with the specified detail message.
|
||||
|
||||
* @param message the detail message.
|
||||
*/
|
||||
constructor(message: kotlin.String) : super(message)
|
||||
open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) {
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID: Long = 456L
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
class OffsetDateTimeAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: OffsetDateTime): String {
|
||||
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value)
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): OffsetDateTime {
|
||||
return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME)
|
||||
}
|
||||
|
||||
}
|
@ -12,5 +12,5 @@ data class RequestConfig(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: Map<String, List<String>> = mapOf()
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf()
|
||||
)
|
@ -20,4 +20,4 @@ val Response.isClientError : Boolean get() = this.code in 400..499
|
||||
/**
|
||||
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
||||
*/
|
||||
val Response.isServerError : Boolean get() = this.code in 500..999
|
||||
val Response.isServerError : Boolean get() = this.code in 500..999
|
||||
|
@ -7,12 +7,17 @@ import java.util.Date
|
||||
|
||||
object Serializer {
|
||||
@JvmStatic
|
||||
val moshi: Moshi = Moshi.Builder()
|
||||
val moshiBuilder: Moshi.Builder = Moshi.Builder()
|
||||
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
|
||||
.add(OffsetDateTimeAdapter())
|
||||
.add(LocalDateTimeAdapter())
|
||||
.add(LocalDateAdapter())
|
||||
.add(UUIDAdapter())
|
||||
.add(ByteArrayAdapter())
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()
|
||||
|
||||
@JvmStatic
|
||||
val moshi: Moshi by lazy {
|
||||
moshiBuilder.build()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user