mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 02:32:45 +00:00
The method buildRequestBodyMultipart in ApiClient.java now recognizes if an input parameter is an instance of List.
This commit is contained in:
@@ -1522,9 +1522,12 @@ public class ApiClient {
|
|||||||
for (Entry<String, Object> param : formParams.entrySet()) {
|
for (Entry<String, Object> param : formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof File) {
|
||||||
File file = (File) param.getValue();
|
File file = (File) param.getValue();
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\"");
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
} else if (param.getValue() instanceof List) {
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
List<File> files = (List<File>) param.getValue();
|
||||||
|
for (File file : files) {
|
||||||
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
||||||
@@ -1548,6 +1551,19 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Content-Disposition Header for the given key and file to the MultipartBody Builder.
|
||||||
|
*
|
||||||
|
* @param mpBuilder MultipartBody.Builder
|
||||||
|
* @param key The key of the Header element
|
||||||
|
* @param file The file to add to the Header
|
||||||
|
*/
|
||||||
|
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||||
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||||
|
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||||
|
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get network interceptor to add it to the httpClient to track download progress for
|
* Get network interceptor to add it to the httpClient to track download progress for
|
||||||
* async requests.
|
* async requests.
|
||||||
|
|||||||
@@ -1317,9 +1317,12 @@ public class ApiClient {
|
|||||||
for (Entry<String, Object> param : formParams.entrySet()) {
|
for (Entry<String, Object> param : formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof File) {
|
||||||
File file = (File) param.getValue();
|
File file = (File) param.getValue();
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\"");
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
} else if (param.getValue() instanceof List) {
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
List<File> files = (List<File>) param.getValue();
|
||||||
|
for (File file : files) {
|
||||||
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
||||||
@@ -1343,6 +1346,19 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Content-Disposition Header for the given key and file to the MultipartBody Builder.
|
||||||
|
*
|
||||||
|
* @param mpBuilder MultipartBody.Builder
|
||||||
|
* @param key The key of the Header element
|
||||||
|
* @param file The file to add to the Header
|
||||||
|
*/
|
||||||
|
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||||
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||||
|
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||||
|
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get network interceptor to add it to the httpClient to track download progress for
|
* Get network interceptor to add it to the httpClient to track download progress for
|
||||||
* async requests.
|
* async requests.
|
||||||
|
|||||||
@@ -1395,9 +1395,12 @@ public class ApiClient {
|
|||||||
for (Entry<String, Object> param : formParams.entrySet()) {
|
for (Entry<String, Object> param : formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof File) {
|
||||||
File file = (File) param.getValue();
|
File file = (File) param.getValue();
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\"");
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
} else if (param.getValue() instanceof List) {
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
List<File> files = (List<File>) param.getValue();
|
||||||
|
for (File file : files) {
|
||||||
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
||||||
@@ -1421,6 +1424,19 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Content-Disposition Header for the given key and file to the MultipartBody Builder.
|
||||||
|
*
|
||||||
|
* @param mpBuilder MultipartBody.Builder
|
||||||
|
* @param key The key of the Header element
|
||||||
|
* @param file The file to add to the Header
|
||||||
|
*/
|
||||||
|
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||||
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||||
|
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||||
|
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get network interceptor to add it to the httpClient to track download progress for
|
* Get network interceptor to add it to the httpClient to track download progress for
|
||||||
* async requests.
|
* async requests.
|
||||||
|
|||||||
@@ -1396,9 +1396,12 @@ public class ApiClient {
|
|||||||
for (Entry<String, Object> param : formParams.entrySet()) {
|
for (Entry<String, Object> param : formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof File) {
|
||||||
File file = (File) param.getValue();
|
File file = (File) param.getValue();
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\"");
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
} else if (param.getValue() instanceof List) {
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
List<File> files = (List<File>) param.getValue();
|
||||||
|
for (File file : files) {
|
||||||
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
||||||
@@ -1422,6 +1425,19 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Content-Disposition Header for the given key and file to the MultipartBody Builder.
|
||||||
|
*
|
||||||
|
* @param mpBuilder MultipartBody.Builder
|
||||||
|
* @param key The key of the Header element
|
||||||
|
* @param file The file to add to the Header
|
||||||
|
*/
|
||||||
|
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||||
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||||
|
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||||
|
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get network interceptor to add it to the httpClient to track download progress for
|
* Get network interceptor to add it to the httpClient to track download progress for
|
||||||
* async requests.
|
* async requests.
|
||||||
|
|||||||
@@ -1415,9 +1415,12 @@ public class ApiClient {
|
|||||||
for (Entry<String, Object> param : formParams.entrySet()) {
|
for (Entry<String, Object> param : formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof File) {
|
||||||
File file = (File) param.getValue();
|
File file = (File) param.getValue();
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"; filename=\"" + file.getName() + "\"");
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
} else if (param.getValue() instanceof List) {
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
List<File> files = (List<File>) param.getValue();
|
||||||
|
for (File file : files) {
|
||||||
|
addPartToMultiPartBuilder(mpBuilder, param.getKey(), file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + param.getKey() + "\"");
|
||||||
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
mpBuilder.addPart(partHeaders, RequestBody.create(parameterToString(param.getValue()), null));
|
||||||
@@ -1441,6 +1444,19 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a Content-Disposition Header for the given key and file to the MultipartBody Builder.
|
||||||
|
*
|
||||||
|
* @param mpBuilder MultipartBody.Builder
|
||||||
|
* @param key The key of the Header element
|
||||||
|
* @param file The file to add to the Header
|
||||||
|
*/
|
||||||
|
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||||
|
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||||
|
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||||
|
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get network interceptor to add it to the httpClient to track download progress for
|
* Get network interceptor to add it to the httpClient to track download progress for
|
||||||
* async requests.
|
* async requests.
|
||||||
|
|||||||
Reference in New Issue
Block a user