diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 265854195041..7287dae8cfff 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -222,6 +222,17 @@ use {{invokerPackage}}\ObjectSerializer; } {{/bodyParams}} + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}], + [{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -237,22 +248,14 @@ use {{invokerPackage}}\ObjectSerializer; } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}], - [{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] - ); - } - {{#authMethods}} {{#isApiKey}} // this endpoint requires API key authentication 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 af6a571b6278..f6998119c30c 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 @@ -872,6 +872,29 @@ paths: description: Output composite schema: $ref: '#/definitions/OuterComposite' + /fake/jsonFormData: + get: + tags: + - fake + summary: test json serialization of form data + description: '' + operationId: testJsonFormData + consumes: + - application/json + parameters: + - name: param + in: formData + description: field1 + required: true + type: string + - name: param2 + in: formData + description: field2 + required: true + type: string + responses: + '200': + description: successful operation securityDefinitions: petstore_auth: type: oauth2 diff --git a/samples/client/petstore-security-test/php/.swagger-codegen/VERSION b/samples/client/petstore-security-test/php/.swagger-codegen/VERSION new file mode 100644 index 000000000000..f9f7450d1359 --- /dev/null +++ b/samples/client/petstore-security-test/php/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file 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 3ce9e2eb5b15..2c6ad2528525 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 @@ -123,7 +123,18 @@ class FakeApi if ($test_code_inject____end____rn_n_r !== null) { $formParams['test code inject */ ' " =end -- \r\n \n \r'] = ObjectSerializer::toFormValue($test_code_inject____end____rn_n_r); } - + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json', '*_/ \" =end --'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json', '*_/ \" =end --'], + ['application/json', '*_/ \" =end --'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -139,22 +150,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/json', '*_/ \" =end --'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/json', '*_/ \" =end --'], - ['application/json', '*_/ \" =end --'] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index 95b1260e5dc6..126db11d8a4c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -82,6 +82,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* | [**testJsonFormData**](docs/Api/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data *Fake_classname_tags123Api* | [**testClassname**](docs/Api/Fake_classname_tags123Api.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 *PetApi* | [**deletePet**](docs/Api/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet 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 74ccd8ece5d1..1691f3d27a80 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 +[**testJsonFormData**](FakeApi.md#testJsonFormData) | **GET** /fake/jsonFormData | test json serialization of form data # **fakeOuterBooleanSerialize** @@ -370,3 +371,49 @@ 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) +# **testJsonFormData** +> testJsonFormData($param, $param2) + +test json serialization of form data + + + +### Example +```php +testJsonFormData($param, $param2); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->testJsonFormData: ', $e->getMessage(), PHP_EOL; +} +?> +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **param** | **string**| field1 | + **param2** | **string**| field2 | + +### 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) + 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 c618684b7b8a..6e34e3eee653 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -126,6 +126,17 @@ class FakeApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -141,22 +152,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - [] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - [], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -273,6 +276,17 @@ class FakeApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -288,22 +302,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - [] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - [], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -420,6 +426,17 @@ class FakeApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -435,22 +452,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - [] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - [], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -567,6 +576,17 @@ class FakeApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -582,22 +602,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - [] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - [], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -718,6 +730,17 @@ class FakeApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -733,22 +756,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - ['application/json'] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -1004,6 +1019,17 @@ class FakeApi $formParams['callback'] = ObjectSerializer::toFormValue($callback); } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml; charset=utf-8', 'application/json; charset=utf-8'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml; charset=utf-8', 'application/json; charset=utf-8'], + ['application/xml; charset=utf-8', 'application/json; charset=utf-8'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -1019,22 +1045,14 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml; charset=utf-8', 'application/json; charset=utf-8'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml; charset=utf-8', 'application/json; charset=utf-8'], - ['application/xml; charset=utf-8', 'application/json; charset=utf-8'] - ); - } - // this endpoint requires HTTP basic authentication if ($this->config->getUsername() !== null || $this->config->getPassword() !== null) { $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword()); @@ -1183,6 +1201,17 @@ class FakeApi $formParams['enum_query_double'] = ObjectSerializer::toFormValue($enum_query_double); } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['*/*'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['*/*'], + ['*/*'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -1198,22 +1227,158 @@ class FakeApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $request = new Request( + 'GET', + $url, + $headers, + $httpBody + ); + + 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( + "[$statusCode] Error connecting to the API ($url)", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + /** + * Operation testJsonFormData + * + * test json serialization of form data + * + * @param string $param field1 (required) + * @param string $param2 field2 (required) + * @throws \Swagger\Client\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function testJsonFormData($param, $param2) + { + $this->testJsonFormDataWithHttpInfo($param, $param2); + } + + /** + * Operation testJsonFormDataWithHttpInfo + * + * test json serialization of form data + * + * @param string $param field1 (required) + * @param string $param2 field2 (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 testJsonFormDataWithHttpInfo($param, $param2) + { + // verify the required parameter 'param' is set + if ($param === null) { + throw new \InvalidArgumentException('Missing the required parameter $param when calling testJsonFormData'); + } + // verify the required parameter 'param2' is set + if ($param2 === null) { + throw new \InvalidArgumentException('Missing the required parameter $param2 when calling testJsonFormData'); + } + + $resourcePath = '/fake/jsonFormData'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + $returnType = ''; + + + + // form params + if ($param !== null) { + $formParams['param'] = ObjectSerializer::toFormValue($param); + } + // form params + if ($param2 !== null) { + $formParams['param2'] = ObjectSerializer::toFormValue($param2); + } + + if ($multipart) { $headers= $this->headerSelector->selectHeadersForMultipart( - ['*/*'] + [] ); } else { $headers = $this->headerSelector->selectHeaders( - ['*/*'], - ['*/*'] + [], + ['application/json'] ); } + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php index a587cbd023af..d501d730bbd0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/Fake_classname_tags123Api.php @@ -130,6 +130,17 @@ class Fake_classname_tags123Api $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -145,22 +156,14 @@ class Fake_classname_tags123Api } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - ['application/json'] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); 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 df94ea0846f7..e1c7f0beeee7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -129,6 +129,17 @@ class PetApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + ['application/json', 'application/xml'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -144,22 +155,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - ['application/json', 'application/xml'] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); @@ -270,6 +273,17 @@ class PetApi } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -285,22 +299,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); @@ -409,6 +415,17 @@ class PetApi + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -424,22 +441,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); @@ -566,6 +575,17 @@ class PetApi + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -581,22 +601,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); @@ -720,6 +732,17 @@ class PetApi } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -735,22 +758,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('api_key'); if ($apiKey !== null) { @@ -875,6 +890,17 @@ class PetApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + ['application/json', 'application/xml'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -890,22 +916,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - ['application/json', 'application/xml'] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); @@ -1022,6 +1040,17 @@ class PetApi $formParams['status'] = ObjectSerializer::toFormValue($status); } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + ['application/x-www-form-urlencoded'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -1037,22 +1066,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - ['application/x-www-form-urlencoded'] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); @@ -1171,6 +1192,17 @@ class PetApi $formParams['file'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue($file), 'rb'); } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['multipart/form-data'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -1186,22 +1218,14 @@ class PetApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - ['multipart/form-data'] - ); - } - // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); 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 42179d66ec91..35908a206713 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -128,6 +128,17 @@ class StoreApi } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -143,22 +154,14 @@ class StoreApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -250,6 +253,17 @@ class StoreApi + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -265,22 +279,14 @@ class StoreApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/json'], - [] - ); - } - // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('api_key'); if ($apiKey !== null) { @@ -412,6 +418,17 @@ class StoreApi } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -427,22 +444,14 @@ class StoreApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -563,6 +572,17 @@ class StoreApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -578,22 +598,14 @@ class StoreApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); 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 65c924fcba3e..5cd4cab7bb16 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -129,6 +129,17 @@ class UserApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -144,22 +155,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -261,6 +264,17 @@ class UserApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -276,22 +290,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -393,6 +399,17 @@ class UserApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -408,22 +425,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -524,6 +533,17 @@ class UserApi } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -539,22 +559,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -656,6 +668,17 @@ class UserApi } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -671,22 +694,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -816,6 +831,17 @@ class UserApi + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -831,22 +857,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -955,6 +973,17 @@ class UserApi + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -970,22 +999,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); @@ -1097,6 +1118,17 @@ class UserApi $_tempBody = $body; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/xml', 'application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/xml', 'application/json'], + [] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -1112,22 +1144,14 @@ class UserApi } $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) } } - if ($httpBody instanceof MultipartStream) { - $headers= $this->headerSelector->selectHeadersForMultipart( - ['application/xml', 'application/json'] - ); - } else { - $headers = $this->headerSelector->selectHeaders( - ['application/xml', 'application/json'], - [] - ); - } - $query = \GuzzleHttp\Psr7\build_query($queryParams); $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/ExceptionTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/ExceptionTest.php index b314b0625e1b..29a0d5d75596 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/ExceptionTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/ExceptionTest.php @@ -6,12 +6,13 @@ use GuzzleHttp\Client; class ExceptionTest extends \PHPUnit_Framework_TestCase { + /** + * @expectedException \Swagger\Client\ApiException + * @expectedExceptionCode 404 + * @expectedExceptionMessage http://petstore.swagger.io/INVALID_URL/store/inventory + */ public function testNotFound() { - $this->expectException(ApiException::class); - $this->expectExceptionCode(404); - $this->expectExceptionMessage('http://petstore.swagger.io/INVALID_URL/store/inventory'); - $config = new Configuration(); $config->setHost('http://petstore.swagger.io/INVALID_URL'); @@ -22,11 +23,12 @@ class ExceptionTest extends \PHPUnit_Framework_TestCase $api->getInventory(); } + /** + * @expectedException \Swagger\Client\ApiException + * @expectedExceptionMessage Could not resolve host + */ public function testWrongHost() { - $this->expectException(ApiException::class); - $this->expectExceptionMessage('Could not resolve host'); - $config = new Configuration(); $config->setHost('http://wrong_host.zxc'); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/RequestTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/RequestTest.php new file mode 100644 index 000000000000..779ae71ab027 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/RequestTest.php @@ -0,0 +1,34 @@ +fakeClient = new FakeHttpClient(); + $this->api = new Api\FakeApi($this->fakeClient); + } + + public function testFormDataEncodingToJson() + { + $this->api->testJsonFormData('value', 'value2'); + + $request = $this->fakeClient->getLastRequest(); + $contentType = $request->getHeader('Content-Type'); + $this->assertEquals(['application/json'], $contentType); + + $requestContent = $request->getBody()->getContents(); + + $expected = json_encode(['param' => 'value', 'param2' => 'value2']); + $this->assertEquals($expected, $requestContent); + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/ResponseTypesTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/ResponseTypesTest.php index 7c6281aec5cb..71eda338ba90 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/ResponseTypesTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/ResponseTypesTest.php @@ -37,13 +37,14 @@ class ResponseTypesTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf(Pet::class, $result); } + /** + * @expectedException \Swagger\Client\ApiException + * @expectedExceptionCode 400 + */ public function testDefinedErrorException() { $statusCode = 400; - $this->expectException(ApiException::class); - $this->expectExceptionCode($statusCode); - $this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}')); $this->api->getPetById(123); } @@ -67,13 +68,14 @@ class ResponseTypesTest extends \PHPUnit_Framework_TestCase // $this->assertInstanceOf(Error::class, $result); // } + /** + * @expectedException \Swagger\Client\ApiException + * @expectedExceptionCode 404 + */ public function testDefaultErrorException() { $statusCode = 404; - $this->expectException(ApiException::class); - $this->expectExceptionCode($statusCode); - $this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}')); $this->api->getPetById(123); }