forked from loafle/openapi-generator-original
PHP: adding the ability to use multipart-form submissions as well as adding formParams to the api
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user