mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Skip null header/form parameters
and fix the bug of getting file name for file parameter
This commit is contained in:
parent
eb4973237b
commit
cf4b4de970
@ -68,7 +68,8 @@ public class {{classname}} {
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/queryParams}}
|
||||
{{#headerParams}}headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{#headerParams}}if ({{paramName}} != null)
|
||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
String[] contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
|
||||
@ -80,18 +81,23 @@ public class {{classname}} {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
{{#formParams}}{{#notFile}}
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
{{/notFile}}{{#isFile}}
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", file.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
|
||||
formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
||||
|
@ -338,18 +338,24 @@ public class PetApi {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
|
||||
hasFields = true;
|
||||
mp.field("name", apiClient.parameterToString(name), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
if (name != null) {
|
||||
hasFields = true;
|
||||
mp.field("name", apiClient.parameterToString(name), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
|
||||
hasFields = true;
|
||||
mp.field("status", apiClient.parameterToString(status), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
if (status != null) {
|
||||
hasFields = true;
|
||||
mp.field("status", apiClient.parameterToString(status), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
formParams.put("name", apiClient.parameterToString(name));
|
||||
formParams.put("status", apiClient.parameterToString(status));
|
||||
if (name != null)
|
||||
formParams.put("name", apiClient.parameterToString(name));
|
||||
if (status != null)
|
||||
formParams.put("status", apiClient.parameterToString(status));
|
||||
|
||||
}
|
||||
|
||||
@ -392,7 +398,8 @@ public class PetApi {
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
|
||||
headerParams.put("api_key", apiClient.parameterToString(apiKey));
|
||||
if (apiKey != null)
|
||||
headerParams.put("api_key", apiClient.parameterToString(apiKey));
|
||||
|
||||
String[] contentTypes = {
|
||||
|
||||
@ -462,18 +469,23 @@ public class PetApi {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
|
||||
hasFields = true;
|
||||
mp.field("additionalMetadata", apiClient.parameterToString(additionalMetadata), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
if (additionalMetadata != null) {
|
||||
hasFields = true;
|
||||
mp.field("additionalMetadata", apiClient.parameterToString(additionalMetadata), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
|
||||
hasFields = true;
|
||||
mp.field("file", file.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
if (file != null) {
|
||||
hasFields = true;
|
||||
mp.field("file", file.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
}
|
||||
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
formParams.put("additionalMetadata", apiClient.parameterToString(additionalMetadata));
|
||||
if (additionalMetadata != null)
|
||||
formParams.put("additionalMetadata", apiClient.parameterToString(additionalMetadata));
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user