Skip to content

Commit 47f355a

Browse files
authored
Merge pull request #7748 from channelengine/master
[PHP] Fix 'multi' query string serialization and array json serialization
2 parents bc4d9f9 + d308689 commit 47f355a

File tree

20 files changed

+261
-157
lines changed

20 files changed

+261
-157
lines changed

modules/swagger-codegen/src/main/resources/php/api.mustache

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ use {{invokerPackage}}\ObjectSerializer;
356356
// query params
357357
{{#collectionFormat}}
358358
if (is_array(${{paramName}})) {
359-
${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{collectionFormat}}', true);
360-
}
359+
$queryParams['{{baseName}}'] = ${{paramName}};
360+
} else
361361
{{/collectionFormat}}
362362
if (${{paramName}} !== null) {
363363
$queryParams['{{baseName}}'] = ObjectSerializer::toQueryValue(${{paramName}});
@@ -426,9 +426,16 @@ use {{invokerPackage}}\ObjectSerializer;
426426
if (isset($_tempBody)) {
427427
// $_tempBody is the method argument, if present
428428
$httpBody = $_tempBody;
429-
// \stdClass has no __toString(), so we should encode it manually
430-
if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
431-
$httpBody = \GuzzleHttp\json_encode($httpBody);
429+
430+
if($headers['Content-Type'] === 'application/json') {
431+
// \stdClass has no __toString(), so we should encode it manually
432+
if ($httpBody instanceof \stdClass) {
433+
$httpBody = \GuzzleHttp\json_encode($httpBody);
434+
}
435+
// array has no __toString(), so we should encode it manually
436+
if(is_array($httpBody)) {
437+
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
438+
}
432439
}
433440
} elseif (count($formParams) > 0) {
434441
if ($multipart) {

samples/client/petstore/php/SwaggerClient-php/README.md

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SwaggerClient-php
2-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
2+
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
33

44
This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
55

@@ -56,41 +56,32 @@ Please follow the [installation procedure](#installation--usage) and then run th
5656
<?php
5757
require_once(__DIR__ . '/vendor/autoload.php');
5858

59-
$apiInstance = new Swagger\Client\Api\AnotherFakeApi(
59+
// Configure OAuth2 access token for authorization: petstore_auth
60+
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
61+
62+
$apiInstance = new Swagger\Client\Api\PetApi(
6063
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
6164
// This is optional, `GuzzleHttp\Client` will be used as default.
62-
new GuzzleHttp\Client()
65+
new GuzzleHttp\Client(),
66+
$config
6367
);
64-
$body = new \Swagger\Client\Model\Client(); // \Swagger\Client\Model\Client | client model
68+
$body = new \Swagger\Client\Model\Pet(); // \Swagger\Client\Model\Pet | Pet object that needs to be added to the store
6569

6670
try {
67-
$result = $apiInstance->testSpecialTags($body);
68-
print_r($result);
71+
$apiInstance->addPet($body);
6972
} catch (Exception $e) {
70-
echo 'Exception when calling AnotherFakeApi->testSpecialTags: ', $e->getMessage(), PHP_EOL;
73+
echo 'Exception when calling PetApi->addPet: ', $e->getMessage(), PHP_EOL;
7174
}
7275

7376
?>
7477
```
7578

7679
## Documentation for API Endpoints
7780

78-
All URIs are relative to *http://petstore.swagger.io:80/v2*
81+
All URIs are relative to *http://petstore.swagger.io/v2*
7982

8083
Class | Method | HTTP request | Description
8184
------------ | ------------- | ------------- | -------------
82-
*AnotherFakeApi* | [**testSpecialTags**](docs/Api/AnotherFakeApi.md#testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
83-
*FakeApi* | [**fakeOuterBooleanSerialize**](docs/Api/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
84-
*FakeApi* | [**fakeOuterCompositeSerialize**](docs/Api/FakeApi.md#fakeoutercompositeserialize) | **POST** /fake/outer/composite |
85-
*FakeApi* | [**fakeOuterNumberSerialize**](docs/Api/FakeApi.md#fakeouternumberserialize) | **POST** /fake/outer/number |
86-
*FakeApi* | [**fakeOuterStringSerialize**](docs/Api/FakeApi.md#fakeouterstringserialize) | **POST** /fake/outer/string |
87-
*FakeApi* | [**testBodyWithQueryParams**](docs/Api/FakeApi.md#testbodywithqueryparams) | **PUT** /fake/body-with-query-params |
88-
*FakeApi* | [**testClientModel**](docs/Api/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \&quot;client\&quot; model
89-
*FakeApi* | [**testEndpointParameters**](docs/Api/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
90-
*FakeApi* | [**testEnumParameters**](docs/Api/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters
91-
*FakeApi* | [**testInlineAdditionalProperties**](docs/Api/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
92-
*FakeApi* | [**testJsonFormData**](docs/Api/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data
93-
*FakeClassnameTags123Api* | [**testClassname**](docs/Api/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case
9485
*PetApi* | [**addPet**](docs/Api/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
9586
*PetApi* | [**deletePet**](docs/Api/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
9687
*PetApi* | [**findPetsByStatus**](docs/Api/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
@@ -99,9 +90,9 @@ Class | Method | HTTP request | Description
9990
*PetApi* | [**updatePet**](docs/Api/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
10091
*PetApi* | [**updatePetWithForm**](docs/Api/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
10192
*PetApi* | [**uploadFile**](docs/Api/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
102-
*StoreApi* | [**deleteOrder**](docs/Api/StoreApi.md#deleteorder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID
93+
*StoreApi* | [**deleteOrder**](docs/Api/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
10394
*StoreApi* | [**getInventory**](docs/Api/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
104-
*StoreApi* | [**getOrderById**](docs/Api/StoreApi.md#getorderbyid) | **GET** /store/order/{order_id} | Find purchase order by ID
95+
*StoreApi* | [**getOrderById**](docs/Api/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
10596
*StoreApi* | [**placeOrder**](docs/Api/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
10697
*UserApi* | [**createUser**](docs/Api/UserApi.md#createuser) | **POST** /user | Create user
10798
*UserApi* | [**createUsersWithArrayInput**](docs/Api/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
@@ -115,42 +106,12 @@ Class | Method | HTTP request | Description
115106

116107
## Documentation For Models
117108

118-
- [AdditionalPropertiesClass](docs/Model/AdditionalPropertiesClass.md)
119-
- [Animal](docs/Model/Animal.md)
120-
- [AnimalFarm](docs/Model/AnimalFarm.md)
121109
- [ApiResponse](docs/Model/ApiResponse.md)
122-
- [ArrayOfArrayOfNumberOnly](docs/Model/ArrayOfArrayOfNumberOnly.md)
123-
- [ArrayOfNumberOnly](docs/Model/ArrayOfNumberOnly.md)
124-
- [ArrayTest](docs/Model/ArrayTest.md)
125-
- [Capitalization](docs/Model/Capitalization.md)
126110
- [Category](docs/Model/Category.md)
127-
- [ClassModel](docs/Model/ClassModel.md)
128-
- [Client](docs/Model/Client.md)
129-
- [EnumArrays](docs/Model/EnumArrays.md)
130-
- [EnumClass](docs/Model/EnumClass.md)
131-
- [EnumTest](docs/Model/EnumTest.md)
132-
- [FormatTest](docs/Model/FormatTest.md)
133-
- [HasOnlyReadOnly](docs/Model/HasOnlyReadOnly.md)
134-
- [MapTest](docs/Model/MapTest.md)
135-
- [MixedPropertiesAndAdditionalPropertiesClass](docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md)
136-
- [Model200Response](docs/Model/Model200Response.md)
137-
- [ModelList](docs/Model/ModelList.md)
138-
- [ModelReturn](docs/Model/ModelReturn.md)
139-
- [Name](docs/Model/Name.md)
140-
- [NumberOnly](docs/Model/NumberOnly.md)
141111
- [Order](docs/Model/Order.md)
142-
- [OuterBoolean](docs/Model/OuterBoolean.md)
143-
- [OuterComposite](docs/Model/OuterComposite.md)
144-
- [OuterEnum](docs/Model/OuterEnum.md)
145-
- [OuterNumber](docs/Model/OuterNumber.md)
146-
- [OuterString](docs/Model/OuterString.md)
147112
- [Pet](docs/Model/Pet.md)
148-
- [ReadOnlyFirst](docs/Model/ReadOnlyFirst.md)
149-
- [SpecialModelName](docs/Model/SpecialModelName.md)
150113
- [Tag](docs/Model/Tag.md)
151114
- [User](docs/Model/User.md)
152-
- [Cat](docs/Model/Cat.md)
153-
- [Dog](docs/Model/Dog.md)
154115

155116

156117
## Documentation For Authorization
@@ -162,16 +123,6 @@ Class | Method | HTTP request | Description
162123
- **API key parameter name**: api_key
163124
- **Location**: HTTP header
164125

165-
## api_key_query
166-
167-
- **Type**: API key
168-
- **API key parameter name**: api_key_query
169-
- **Location**: URL query string
170-
171-
## http_basic_test
172-
173-
- **Type**: HTTP basic authentication
174-
175126
## petstore_auth
176127

177128
- **Type**: OAuth

samples/client/petstore/php/SwaggerClient-php/docs/Api/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Swagger\Client\PetApi
22

3-
All URIs are relative to *http://petstore.swagger.io:80/v2*
3+
All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------

samples/client/petstore/php/SwaggerClient-php/docs/Api/StoreApi.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Swagger\Client\StoreApi
22

3-
All URIs are relative to *http://petstore.swagger.io:80/v2*
3+
All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**deleteOrder**](StoreApi.md#deleteOrder) | **DELETE** /store/order/{order_id} | Delete purchase order by ID
7+
[**deleteOrder**](StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
88
[**getInventory**](StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status
9-
[**getOrderById**](StoreApi.md#getOrderById) | **GET** /store/order/{order_id} | Find purchase order by ID
9+
[**getOrderById**](StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
1010
[**placeOrder**](StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet
1111

1212

samples/client/petstore/php/SwaggerClient-php/docs/Api/UserApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Swagger\Client\UserApi
22

3-
All URIs are relative to *http://petstore.swagger.io:80/v2*
3+
All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------

0 commit comments

Comments
 (0)