mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 00:43:46 +00:00
Merge remote-tracking branch 'origin/5.3.x' into 6.0.x
This commit is contained in:
@@ -11,7 +11,6 @@ src/main/kotlin/org/openapitools/client/apis/EnumApi.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/ApplicationDelegates.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
|
||||
@@ -23,5 +22,6 @@ 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/PetEnum.kt
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
6.0.0-SNAPSHOT
|
||||
<<<<<<< HEAD
|
||||
6.0.0-SNAPSHOT
|
||||
=======
|
||||
5.3.0-SNAPSHOT
|
||||
>>>>>>> origin/5.3.x
|
||||
|
||||
@@ -7,7 +7,7 @@ wrapper {
|
||||
}
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.4.30'
|
||||
ext.kotlin_version = '1.5.10'
|
||||
|
||||
repositories {
|
||||
maven { url "https://repo1.maven.org/maven2" }
|
||||
@@ -28,9 +28,9 @@ 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.11.0"
|
||||
compile "com.squareup.okhttp3:okhttp:4.9.0"
|
||||
testCompile "io.kotlintest:kotlintest-runner-junit5:3.4.2"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
implementation "com.squareup.moshi:moshi-kotlin:1.12.0"
|
||||
implementation "com.squareup.okhttp3:okhttp:4.9.1"
|
||||
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class EnumApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
fun getEnum() : PetEnum {
|
||||
val localVariableConfig = getEnumRequestConfig()
|
||||
|
||||
val localVarResponse = request<PetEnum>(
|
||||
val localVarResponse = request<Unit, PetEnum>(
|
||||
localVariableConfig
|
||||
)
|
||||
|
||||
@@ -70,20 +70,18 @@ class EnumApi(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) {
|
||||
*
|
||||
* @return RequestConfig
|
||||
*/
|
||||
fun getEnumRequestConfig() : RequestConfig {
|
||||
val localVariableBody: kotlin.Any? = null
|
||||
fun getEnumRequestConfig() : RequestConfig<Unit> {
|
||||
val localVariableBody = null
|
||||
val localVariableQuery: MultiValueMap = mutableMapOf()
|
||||
val localVariableHeaders: MutableMap<String, String> = mutableMapOf()
|
||||
|
||||
val localVariableConfig = RequestConfig(
|
||||
|
||||
return RequestConfig(
|
||||
method = RequestMethod.GET,
|
||||
path = "/enum",
|
||||
query = localVariableQuery,
|
||||
headers = localVariableHeaders,
|
||||
body = localVariableBody
|
||||
)
|
||||
|
||||
return localVariableConfig
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.asRequestBody
|
||||
@@ -12,17 +11,17 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
import java.io.File
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.net.URLConnection
|
||||
import java.nio.file.Files
|
||||
import java.util.Date
|
||||
import java.time.LocalDate
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalTime
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.OffsetTime
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
@@ -62,9 +61,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
|
||||
protected inline fun <reified T> requestBody(content: T, mediaType: String = JsonMediaType): RequestBody =
|
||||
when {
|
||||
content is File -> content.asRequestBody(
|
||||
mediaType.toMediaTypeOrNull()
|
||||
)
|
||||
content is File -> content.asRequestBody(mediaType.toMediaTypeOrNull())
|
||||
mediaType == FormDataMediaType -> {
|
||||
MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
@@ -119,7 +116,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
if (T::class.java == File::class.java) {
|
||||
// return tempfile
|
||||
val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile()
|
||||
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
|
||||
f.deleteOnExit()
|
||||
val out = BufferedWriter(FileWriter(f))
|
||||
out.write(bodyContent)
|
||||
@@ -133,7 +130,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
|
||||
|
||||
protected inline fun <reified T: Any?> request(requestConfig: RequestConfig): ApiInfrastructureResponse<T?> {
|
||||
protected inline fun <reified I, reified T: Any?> request(requestConfig: RequestConfig<I>): ApiInfrastructureResponse<T?> {
|
||||
val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.")
|
||||
|
||||
val url = httpUrl.newBuilder()
|
||||
@@ -164,7 +161,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
}
|
||||
|
||||
// TODO: support multiple contentType options here.
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").toLowerCase()
|
||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||
|
||||
val request = when (requestConfig.method) {
|
||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||
@@ -179,57 +176,46 @@ open class ApiClient(val baseUrl: String) {
|
||||
}.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.toLowerCase()
|
||||
val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.getDefault())
|
||||
|
||||
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
|
||||
when {
|
||||
response.isRedirect -> return Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
return when {
|
||||
response.isRedirect -> Redirection(
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isInformational -> return Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
response.isInformational -> Informational(
|
||||
response.message,
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isSuccessful -> return Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
response.isSuccessful -> Success(
|
||||
responseBody(response.body, accept),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
response.isClientError -> return ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
response.isClientError -> ClientError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
else -> return ServerError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
else -> ServerError(
|
||||
response.message,
|
||||
response.body?.string(),
|
||||
response.code,
|
||||
response.headers.toMultimap()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun parameterToString(value: Any?): String {
|
||||
when (value) {
|
||||
null -> {
|
||||
return ""
|
||||
}
|
||||
is Array<*> -> {
|
||||
return toMultiValue(value, "csv").toString()
|
||||
}
|
||||
is Iterable<*> -> {
|
||||
return toMultiValue(value, "csv").toString()
|
||||
}
|
||||
is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime, is Date -> {
|
||||
return parseDateToQueryString<Any>(value)
|
||||
}
|
||||
else -> {
|
||||
return value.toString()
|
||||
}
|
||||
}
|
||||
protected fun parameterToString(value: Any?): String = when (value) {
|
||||
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 ->
|
||||
parseDateToQueryString(value)
|
||||
else -> value.toString()
|
||||
}
|
||||
|
||||
protected inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||
|
||||
@@ -8,10 +8,10 @@ package org.openapitools.client.infrastructure
|
||||
* NOTE: Headers is a Map<String,String> because rfc2616 defines
|
||||
* multi-valued headers as csv-only.
|
||||
*/
|
||||
data class RequestConfig(
|
||||
data class RequestConfig<T>(
|
||||
val method: RequestMethod,
|
||||
val path: String,
|
||||
val headers: MutableMap<String, String> = mutableMapOf(),
|
||||
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
||||
val body: kotlin.Any? = null
|
||||
val body: T? = null
|
||||
)
|
||||
@@ -12,6 +12,7 @@ object Serializer {
|
||||
.add(LocalDateAdapter())
|
||||
.add(UUIDAdapter())
|
||||
.add(ByteArrayAdapter())
|
||||
.add(URIAdapter())
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.add(BigDecimalAdapter())
|
||||
.add(BigIntegerAdapter())
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.net.URI
|
||||
|
||||
class URIAdapter {
|
||||
@ToJson
|
||||
fun toJson(uri: URI) = uri.toString()
|
||||
|
||||
@FromJson
|
||||
fun fromJson(s: String): URI = URI.create(s)
|
||||
}
|
||||
@@ -9,5 +9,5 @@ class UUIDAdapter {
|
||||
fun toJson(uuid: UUID) = uuid.toString()
|
||||
|
||||
@FromJson
|
||||
fun fromJson(s: String) = UUID.fromString(s)
|
||||
fun fromJson(s: String): UUID = UUID.fromString(s)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.squareup.moshi.Json
|
||||
* Values: MY_FIRST_VALUE,MY_SECOND_VALUE
|
||||
*/
|
||||
|
||||
|
||||
enum class PetEnum(val value: kotlin.String) {
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user