forked from loafle/openapi-generator-original
[kotlin-client][jvm-spring-restclient] Extract data from PartConfig for multipart/form-data requests (#20598)
This commit is contained in:
parent
9a9c1087be
commit
c74dfa3b3e
@ -46,8 +46,23 @@ import org.springframework.util.LinkedMultiValueMap
|
|||||||
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
||||||
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
|
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
|
||||||
|
|
||||||
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>) =
|
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>): RestClient.RequestBodySpec {
|
||||||
apply { if (requestConfig.body != null) body(requestConfig.body) }
|
when {
|
||||||
|
requestConfig.headers[HttpHeaders.CONTENT_TYPE] == MediaType.MULTIPART_FORM_DATA_VALUE -> {
|
||||||
|
val parts = LinkedMultiValueMap<String, Any>()
|
||||||
|
(requestConfig.body as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
if (part.body != null) {
|
||||||
|
parts.add(name, part.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return apply { body(parts) }
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
return apply { if (requestConfig.body != null) body(requestConfig.body) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||||
|
@ -46,8 +46,23 @@ open class ApiClient(protected val client: RestClient) {
|
|||||||
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
||||||
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
|
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
|
||||||
|
|
||||||
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>) =
|
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>): RestClient.RequestBodySpec {
|
||||||
apply { if (requestConfig.body != null) body(requestConfig.body) }
|
when {
|
||||||
|
requestConfig.headers[HttpHeaders.CONTENT_TYPE] == MediaType.MULTIPART_FORM_DATA_VALUE -> {
|
||||||
|
val parts = LinkedMultiValueMap<String, Any>()
|
||||||
|
(requestConfig.body as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
if (part.body != null) {
|
||||||
|
parts.add(name, part.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return apply { body(parts) }
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
return apply { if (requestConfig.body != null) body(requestConfig.body) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||||
|
@ -46,8 +46,23 @@ open class ApiClient(protected val client: RestClient) {
|
|||||||
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
private fun <I> RestClient.RequestBodySpec.headers(requestConfig: RequestConfig<I>) =
|
||||||
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
|
apply { requestConfig.headers.forEach { (name, value) -> header(name, value) } }
|
||||||
|
|
||||||
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>) =
|
private fun <I : Any> RestClient.RequestBodySpec.nullableBody(requestConfig: RequestConfig<I>): RestClient.RequestBodySpec {
|
||||||
apply { if (requestConfig.body != null) body(requestConfig.body) }
|
when {
|
||||||
|
requestConfig.headers[HttpHeaders.CONTENT_TYPE] == MediaType.MULTIPART_FORM_DATA_VALUE -> {
|
||||||
|
val parts = LinkedMultiValueMap<String, Any>()
|
||||||
|
(requestConfig.body as Map<String, PartConfig<*>>).forEach { (name, part) ->
|
||||||
|
if (part.body != null) {
|
||||||
|
parts.add(name, part.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return apply { body(parts) }
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
return apply { if (requestConfig.body != null) body(requestConfig.body) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
inline fun <reified T: Any> parseDateToQueryString(value : T): String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user