Skip to content

Commit

Permalink
[PHP] Fix #5338: InvalidArgumentException (#6685)
Browse files Browse the repository at this point in the history
* Add endpoint definition which reproduces #5338 bug

* Update samples

* Add test case which reproduces #5338 bug

* Fix "InvalidArgumentException: Invalid resource type: object"

* Update samples

- ./bin/php-petstore.sh
- ./bin/security/php-petstore.sh
  • Loading branch information
ackintosh authored and wing328 committed Oct 17, 2017
1 parent 381acd2 commit 07b408a
Show file tree
Hide file tree
Showing 12 changed files with 488 additions and 64 deletions.
8 changes: 6 additions & 2 deletions modules/swagger-codegen/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,12 @@ protected function testCodeInjectEndRnNRRequest($test_code_inject____end____rn_n

// 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 = [];
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/php/SwaggerClient-php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$api_instance = new Swagger\Client\Api\FakeApi(new \Http\Adapter\Guzzle6\Client());
$param = new \stdClass; // object | request body

try {
$api_instance->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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ protected function testSpecialTagsRequest($body)

// 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 = [];
Expand Down
Loading

0 comments on commit 07b408a

Please sign in to comment.