Merge remote-tracking branch 'origin/master' into 6.0.x

This commit is contained in:
William Cheng
2022-01-02 15:41:37 +08:00
2007 changed files with 39758 additions and 48375 deletions

View File

@@ -10,7 +10,7 @@ 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/ApiInfrastructureResponse.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
@@ -22,6 +22,7 @@ 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/SerializerHelper.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/ModelWithEnumPropertyHavingDefault.kt

View File

@@ -20,10 +20,14 @@
package org.openapitools.client.apis
import java.io.IOException
import org.openapitools.client.models.ModelWithEnumPropertyHavingDefault
import com.squareup.moshi.Json
import org.openapitools.client.infrastructure.ApiClient
import org.openapitools.client.infrastructure.ApiInfrastructureResponse
import org.openapitools.client.infrastructure.ApiResponse
import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ClientError
import org.openapitools.client.infrastructure.ServerException
@@ -47,12 +51,14 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
*
*
* @return ModelWithEnumPropertyHavingDefault
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
* @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)
@Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun operation() : ModelWithEnumPropertyHavingDefault {
val localVarResponse = operationWithHttpInfo()
@@ -74,14 +80,13 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
/**
*
*
* @return ApiInfrastructureResponse<ModelWithEnumPropertyHavingDefault?>
* @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
* @return ApiResponse<ModelWithEnumPropertyHavingDefault?>
* @throws IllegalStateException If the request is not correctly configured
* @throws IOException Rethrows the OkHttp execute method exception
*/
@Suppress("UNCHECKED_CAST")
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
fun operationWithHttpInfo() : ApiInfrastructureResponse<ModelWithEnumPropertyHavingDefault?> {
@Throws(IllegalStateException::class, IOException::class)
fun operationWithHttpInfo() : ApiResponse<ModelWithEnumPropertyHavingDefault?> {
val localVariableConfig = operationRequestConfig()
return request<Unit, ModelWithEnumPropertyHavingDefault>(
@@ -98,6 +103,7 @@ class DefaultApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath
val localVariableBody = null
val localVariableQuery: MultiValueMap = mutableMapOf()
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
localVariableHeaders["Accept"] = "application/json"
return RequestConfig(
method = RequestMethod.GET,

View File

@@ -25,7 +25,6 @@ import java.time.LocalDateTime
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.OffsetTime
import java.util.Date
import java.util.Locale
import com.squareup.moshi.adapter
@@ -105,7 +104,7 @@ open class ApiClient(val baseUrl: String) {
}
}.build()
}
mediaType == JsonMediaType -> {
mediaType.startsWith("application/") && mediaType.endsWith("json") ->
if (content == null) {
EMPTY_REQUEST
} else {
@@ -114,7 +113,6 @@ open class ApiClient(val baseUrl: String) {
mediaType.toMediaTypeOrNull()
)
}
}
mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
@@ -138,14 +136,15 @@ open class ApiClient(val baseUrl: String) {
out.close()
return f as T
}
return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter<T>().fromJson(bodyContent)
return when {
mediaType==null || (mediaType.startsWith("application/") && mediaType.endsWith("json")) ->
Serializer.moshi.adapter<T>().fromJson(bodyContent)
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
}
}
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiInfrastructureResponse<T?> {
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiResponse<T?> {
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
val url = httpUrl.newBuilder()
@@ -167,11 +166,11 @@ open class ApiClient(val baseUrl: String) {
}
val headers = requestConfig.headers
if(headers[ContentType] ?: "" == "") {
if(headers[ContentType].isNullOrEmpty()) {
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
}
if(headers[Accept] ?: "" == "") {
if(headers[Accept].isNullOrEmpty()) {
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
}
@@ -229,7 +228,7 @@ open class ApiClient(val baseUrl: String) {
null -> ""
is Array<*> -> toMultiValue(value, "csv").toString()
is Iterable<*> -> toMultiValue(value, "csv").toString()
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime, is Date ->
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime ->
parseDateToQueryString(value)
else -> value.toString()
}

View File

@@ -6,7 +6,7 @@ enum class ResponseType {
interface Response
abstract class ApiInfrastructureResponse<T>(val responseType: ResponseType): Response {
abstract class ApiResponse<T>(val responseType: ResponseType): Response {
abstract val statusCode: Int
abstract val headers: Map<String,List<String>>
}
@@ -15,29 +15,29 @@ class Success<T>(
val data: T,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
): ApiInfrastructureResponse<T>(ResponseType.Success)
): ApiResponse<T>(ResponseType.Success)
class Informational<T>(
val statusText: String,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.Informational)
) : ApiResponse<T>(ResponseType.Informational)
class Redirection<T>(
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.Redirection)
) : ApiResponse<T>(ResponseType.Redirection)
class ClientError<T>(
val message: String? = null,
val body: Any? = null,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>> = mapOf()
) : ApiInfrastructureResponse<T>(ResponseType.ClientError)
) : ApiResponse<T>(ResponseType.ClientError)
class ServerError<T>(
val message: String? = null,
val body: Any? = null,
override val statusCode: Int = -1,
override val headers: Map<String, List<String>>
): ApiInfrastructureResponse<T>(ResponseType.ServerError)
): ApiResponse<T>(ResponseType.ServerError)

View File

@@ -1,6 +1,7 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.EnumJsonAdapter
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
object Serializer {
@@ -18,6 +19,7 @@ object Serializer {
@JvmStatic
val moshi: Moshi by lazy {
SerializerHelper.addEnumUnknownDefaultCase(moshiBuilder)
moshiBuilder.build()
}
}

View File

@@ -0,0 +1,12 @@
package org.openapitools.client.infrastructure
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.EnumJsonAdapter
object SerializerHelper {
fun addEnumUnknownDefaultCase(moshiBuilder: Moshi.Builder): Moshi.Builder {
return moshiBuilder
.add(org.openapitools.client.models.ModelWithEnumPropertyHavingDefault.PropertyName::class.java, EnumJsonAdapter.create(org.openapitools.client.models.ModelWithEnumPropertyHavingDefault.PropertyName::class.java)
.withUnknownFallback(org.openapitools.client.models.ModelWithEnumPropertyHavingDefault.PropertyName.unknownDefaultOpenApi))
}
}

View File

@@ -43,10 +43,11 @@ data class ModelWithEnumPropertyHavingDefault (
/**
*
*
* Values: vALUE
* Values: vALUE,unknownDefaultOpenApi
*/
enum class PropertyName(val value: kotlin.String) {
@Json(name = "VALUE") vALUE("VALUE");
@Json(name = "VALUE") vALUE("VALUE"),
@Json(name = "unknown_default_open_api") unknownDefaultOpenApi("unknown_default_open_api");
}
}