diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index a360a0e87bf..7ba928ce184 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -417,8 +417,12 @@ use {{invokerPackage}}\ObjectSerializer; // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index 2510e6cc9ef..c947e95d926 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -898,6 +898,27 @@ paths: responses: '200': description: successful operation + /fake/inline-additionalProperties: + post: + tags: + - fake + summary: test inline additionalProperties + description: '' + operationId: testInlineAdditionalProperties + consumes: + - application/json + parameters: + - name: param + in: body + description: request body + required: true + schema: + type: object + additionalProperties: + type: string + responses: + '200': + description: successful operation /another-fake/dummy: patch: tags: diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php index c2e0132a490..16ad474af26 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -246,8 +246,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index 83b6d6e01a1..087c3105f8d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -83,6 +83,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**testClientModel**](docs/Api/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model *FakeApi* | [**testEndpointParameters**](docs/Api/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**testEnumParameters**](docs/Api/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters +*FakeApi* | [**testInlineAdditionalProperties**](docs/Api/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties *FakeApi* | [**testJsonFormData**](docs/Api/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data *FakeClassnameTags123Api* | [**testClassname**](docs/Api/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case *PetApi* | [**addPet**](docs/Api/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md index 20958d97da2..845ab2f8a02 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**testClientModel**](FakeApi.md#testClientModel) | **PATCH** /fake | To test \"client\" model [**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 [**testEnumParameters**](FakeApi.md#testEnumParameters) | **GET** /fake | To test enum parameters +[**testInlineAdditionalProperties**](FakeApi.md#testInlineAdditionalProperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties [**testJsonFormData**](FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data @@ -371,6 +372,50 @@ No authorization required [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) +# **testInlineAdditionalProperties** +> testInlineAdditionalProperties($param) + +test inline additionalProperties + + + +### Example +```php +testInlineAdditionalProperties($param); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->testInlineAdditionalProperties: ', $e->getMessage(), PHP_EOL; +} +?> +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **param** | **object**| request body | + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + # **testJsonFormData** > testJsonFormData($param, $param2) diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php index 88ca1e9271f..a5980f76cc2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/AnotherFakeApi.php @@ -288,8 +288,12 @@ class AnotherFakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index aec0a279a83..61d4e4a3095 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -278,8 +278,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -520,8 +524,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -762,8 +770,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1004,8 +1016,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1256,8 +1272,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1654,8 +1674,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1937,8 +1961,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1981,6 +2009,225 @@ class FakeApi ); } + /** + * Operation testInlineAdditionalProperties + * + * test inline additionalProperties + * + * @param object $param request body (required) + * + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function testInlineAdditionalProperties($param) + { + $this->testInlineAdditionalPropertiesWithHttpInfo($param); + } + + /** + * Operation testInlineAdditionalPropertiesWithHttpInfo + * + * test inline additionalProperties + * + * @param object $param request body (required) + * + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function testInlineAdditionalPropertiesWithHttpInfo($param) + { + $returnType = ''; + $request = $this->testInlineAdditionalPropertiesRequest($param); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation testInlineAdditionalPropertiesAsync + * + * test inline additionalProperties + * + * @param object $param request body (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testInlineAdditionalPropertiesAsync($param) + { + return $this->testInlineAdditionalPropertiesAsyncWithHttpInfo($param) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation testInlineAdditionalPropertiesAsyncWithHttpInfo + * + * test inline additionalProperties + * + * @param object $param request body (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function testInlineAdditionalPropertiesAsyncWithHttpInfo($param) + { + $returnType = ''; + $request = $this->testInlineAdditionalPropertiesRequest($param); + + return $this->client + ->sendAsync($request) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'testInlineAdditionalProperties' + * + * @param object $param request body (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function testInlineAdditionalPropertiesRequest($param) + { + // verify the required parameter 'param' is set + if ($param === null) { + throw new \InvalidArgumentException( + 'Missing the required parameter $param when calling testInlineAdditionalProperties' + ); + } + + $resourcePath = '/fake/inline-additionalProperties'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // body params + $_tempBody = null; + if (isset($param)) { + $_tempBody = $param; + } + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($_tempBody)) { + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation testJsonFormData * @@ -2168,8 +2415,12 @@ class FakeApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php index d51d3fdf215..3e306d423a3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeClassnameTags123Api.php @@ -288,8 +288,12 @@ class FakeClassnameTags123Api // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index 08b0596b7d5..313e0f2882d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -251,8 +251,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -484,8 +488,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -744,8 +752,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1004,8 +1016,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1265,8 +1281,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1485,8 +1505,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1727,8 +1751,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -2007,8 +2035,12 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index 684f67f65d4..9424f62693e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -256,8 +256,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -494,8 +498,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -763,8 +771,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1015,8 +1027,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index b2517fd4479..ce31171cef1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -251,8 +251,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -466,8 +470,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -681,8 +689,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -901,8 +913,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1158,8 +1174,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1426,8 +1446,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1627,8 +1651,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; @@ -1861,8 +1889,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php index 25e18742ed3..37877556d01 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/ParametersTest.php @@ -45,6 +45,16 @@ class ParametersTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['string1,string2'], $headers['enum_header_string_array']); } + public function testInlineAdditionalProperties() + { + $param = new \stdClass(); + $param->foo = 'bar'; + $this->fakeApi->testInlineAdditionalProperties($param); + + $request = $this->fakeHttpClient->getLastRequest(); + $this->assertSame('{"foo":"bar"}', $request->getBody()->getContents()); + } + // missing example for collection path param in config // public function testPathParamCollection() // {