mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-08 20:56:11 +00:00
[kotlin] Fix empty body with POST/etc in OkHttp client (#13666)
This commit is contained in:
@@ -343,7 +343,7 @@ import com.squareup.moshi.adapter
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -351,16 +351,16 @@ import com.squareup.moshi.adapter
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -164,16 +164,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -164,16 +164,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -184,16 +184,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -184,16 +184,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -190,16 +190,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -187,16 +187,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -183,16 +183,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -166,16 +166,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
// take content-type/accept from spec or set to default (application/json) if not defined
|
// take content-type/accept from spec or set to default (application/json) if not defined
|
||||||
if (requestConfig.headers[ContentType].isNullOrEmpty()) {
|
if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) {
|
||||||
requestConfig.headers[ContentType] = JsonMediaType
|
requestConfig.headers[ContentType] = JsonMediaType
|
||||||
}
|
}
|
||||||
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
if (requestConfig.headers[Accept].isNullOrEmpty()) {
|
||||||
@@ -185,16 +185,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
|
|||||||
}
|
}
|
||||||
val headers = requestConfig.headers
|
val headers = requestConfig.headers
|
||||||
|
|
||||||
if(headers[ContentType].isNullOrEmpty()) {
|
if (headers[Accept].isNullOrEmpty()) {
|
||||||
throw kotlin.IllegalStateException("Missing Content-Type header. This is required.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if(headers[Accept].isNullOrEmpty()) {
|
|
||||||
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
throw kotlin.IllegalStateException("Missing Accept header. This is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support multiple contentType options here.
|
val contentType = if (headers[ContentType] != null) {
|
||||||
val contentType = (headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
// TODO: support multiple contentType options here.
|
||||||
|
(headers[ContentType] as String).substringBefore(";").lowercase(Locale.getDefault())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val request = when (requestConfig.method) {
|
val request = when (requestConfig.method) {
|
||||||
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType))
|
||||||
|
|||||||
Reference in New Issue
Block a user