diff --git a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache index 7e1f24f49b69..f8a602963b64 100644 --- a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache @@ -65,7 +65,7 @@ class APIClient { $headers[] = "api_key: " . $this->apiKey; } - if (is_object($postData) or is_array($postData)) { + if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) { $postData = json_encode($this->sanitizeForSerialization($postData)); } diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 82ea71740321..d2349b18522e 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -44,6 +44,7 @@ class {{classname}} { $method = "{{httpMethod}}"; $queryParams = array(); $headerParams = array(); + $formParams = array(); $headerParams['Accept'] = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}'; $headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}'; @@ -60,12 +61,21 @@ class {{classname}} { $resourcePath = str_replace("{" . "{{paramName}}" . "}", $this->apiClient->toPathValue(${{paramName}}), $resourcePath); }{{/pathParams}} + {{#formParams}} + if (${{paramName}} != null) { + $formParams[{{paramName}}] = {{#isFile}}'@' . {{/isFile}}${{paramName}} + }{{/formParams}} {{#bodyParams}}// body params $body = null; if (isset(${{paramName}})) { $body = ${{paramName}}; + }{{/bodyParams}} + + $body = $body ?: $formParams; + + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $body = http_build_query($body); } - {{/bodyParams}} // make the API Call $response = $this->apiClient->callAPI($resourcePath, $method,