Skip to content

Commit

Permalink
Add group parameter support to PHP client (#1337)
Browse files Browse the repository at this point in the history
* add group parameter support to php template

* more update for group parameter

* fix call to protect function

* fix missing $

* update based on feedback

* create fake endpoint to test group parameters

* sync fake petstore spec v2, v3

* fix php doc for group parameters

* update petstore samples

* update fake petstore spec v2

* update petstore samples

* fix spec and update samples
  • Loading branch information
wing328 committed Oct 29, 2018
1 parent d80f3a6 commit aced89f
Show file tree
Hide file tree
Showing 121 changed files with 3,957 additions and 30 deletions.
45 changes: 36 additions & 9 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Expand Up @@ -89,6 +89,10 @@ use {{invokerPackage}}\ObjectSerializer;
* {{.}}
*
{{/description}}
{{#vendorExtensions.x-group-parameters}}
* Note: the input parameter is an associative array with the keys listed as the parameter name below
*
{{/vendorExtensions.x-group-parameters}}
{{#allParams}}
* @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
Expand All @@ -97,9 +101,9 @@ use {{invokerPackage}}\ObjectSerializer;
* @throws \InvalidArgumentException
* @return {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
public function {{operationId}}({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
{{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
{{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{#returnType}}
return $response;{{/returnType}}
}

Expand All @@ -114,6 +118,10 @@ use {{invokerPackage}}\ObjectSerializer;
* {{.}}
*
{{/description}}
{{#vendorExtensions.x-group-parameters}}
* Note: the inpput parameter is an associative array with the keys listed as the parameter name below
*
{{/vendorExtensions.x-group-parameters}}
{{#allParams}}
* @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
Expand All @@ -122,9 +130,9 @@ use {{invokerPackage}}\ObjectSerializer;
* @throws \InvalidArgumentException
* @return array of {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings)
*/
public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
public function {{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
$request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
$request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}{{#allParams}}$associative_array['{{paramName}}']{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}});

try {
$options = $this->createHttpClientOption();
Expand Down Expand Up @@ -226,16 +234,20 @@ use {{invokerPackage}}\ObjectSerializer;
* {{.}}
*
{{/description}}
{{#vendorExtensions.x-group-parameters}}
* Note: the inpput parameter is an associative array with the keys listed as the parameter name below
*
{{/vendorExtensions.x-group-parameters}}
{{#allParams}}
* @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function {{operationId}}Async({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
public function {{operationId}}Async({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
return $this->{{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
return $this->{{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
->then(
function ($response) {
return $response[0];
Expand All @@ -252,17 +264,21 @@ use {{invokerPackage}}\ObjectSerializer;
* {{.}}
*
{{/description}}
{{#vendorExtensions.x-group-parameters}}
* Note: the inpput parameter is an associative array with the keys listed as the parameter name below
*
{{/vendorExtensions.x-group-parameters}}
{{#allParams}}
* @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function {{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
public function {{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
$returnType = '{{returnType}}';
$request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
$request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});

return $this->client
->sendAsync($request, $this->createHttpClientOption())
Expand Down Expand Up @@ -306,15 +322,26 @@ use {{invokerPackage}}\ObjectSerializer;
/**
* Create request for operation '{{{operationId}}}'
*
{{#vendorExtensions.x-group-parameters}}
* Note: the input parameter is an associative array with the keys listed as the parameter name below
*
{{/vendorExtensions.x-group-parameters}}
{{#allParams}}
* @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
protected function {{operationId}}Request({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
protected function {{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
{
{{#vendorExtensions.x-group-parameters}}
// unbox the parameters from the associative array
{{#allParams}}
${{paramName}} = array_key_exists('{{paramName}}', $associative_array) ? $associative_array['{{paramName}}'] : {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}};
{{/allParams}}

{{/vendorExtensions.x-group-parameters}}
{{#allParams}}
{{#required}}
// verify the required parameter '{{paramName}}' is set
Expand Down
30 changes: 24 additions & 6 deletions modules/openapi-generator/src/main/resources/php/api_doc.mustache
Expand Up @@ -21,31 +21,45 @@ Method | HTTP request | Description
```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}

{{#hasAuthMethods}}
{{#authMethods}}
{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()
->setUsername('YOUR_USERNAME')
->setPassword('YOUR_PASSWORD');
{{/isBasic}}{{#isApiKey}}
{{/isBasic}}
{{#isApiKey}}
// Configure API key authorization: {{{name}}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKey('{{{keyParamName}}}', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');{{/isApiKey}}{{#isOAuth}}
// $config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');
{{/isApiKey}}
{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}}
{{/hasAuthMethods}}
$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
{{/isOAuth}}
{{/authMethods}}

{{/hasAuthMethods}}
$apiInstance = new {{invokerPackage}}\Api\{{classname}}(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(){{#hasAuthMethods}},
$config{{/hasAuthMethods}}
);
{{^vendorExtensions.x-group-parameters}}
{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
{{/vendorExtensions.x-group-parameters}}
{{#vendorExtensions.x-group-parameters}}
{{#allParams}}$associate_array['{{paramName}}'] = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
{{/vendorExtensions.x-group-parameters}}

try {
{{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
{{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associate_array{{/vendorExtensions.x-group-parameters}});{{#returnType}}
print_r($result);{{/returnType}}
} catch (Exception $e) {
echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL;
Expand All @@ -54,6 +68,10 @@ try {
```

### Parameters
{{#vendorExtensions.x-group-parameters}}
Note: the input parameter is an associative array with the keys listed as the parameter name below.

{{/vendorExtensions.x-group-parameters}}
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}
Expand Down
Expand Up @@ -792,6 +792,30 @@ paths:
description: User not found
security:
- http_basic_test: []
delete:
tags:
- fake
summary: Fake endpoint to test group parameters (optional)
description: Fake endpoint to test group parameters (optional)
operationId: testGroupParameters
x-group-parameters: true
parameters:
- name: string_group
type: integer
in: query
description: String in group parameters
- name: boolean_group
type: boolean
in: header
description: Boolean in group parameters
- name: int64_group
type: integer
format: int64
in: query
description: Integer in group parameters
responses:
'400':
description: Someting wrong
/fake/outer/number:
post:
tags:
Expand Down
Expand Up @@ -765,6 +765,33 @@ paths:
- double
- pattern_without_delimiter
- byte
delete:
tags:
- fake
summary: Fake endpoint to test group parameters (optional)
description: Fake endpoint to test group parameters (optional)
operationId: testGroupParameters
x-group-parameters: true
parameters:
- name: string_group
in: query
description: String in group parameters
schema:
type: integer
- name: boolean_group
in: header
description: Boolean in group parameters
schema:
type: boolean
- name: int64_group
in: query
description: Integer in group parameters
schema:
type: integer
format: int64
responses:
'400':
description: Someting wrong
/fake/outer/number:
post:
tags:
Expand Down Expand Up @@ -911,7 +938,7 @@ paths:
- $another-fake?
summary: To test special tags
description: To test special tags and operation ID starting with number
operationId: 123_test_@#$%_special_tags
operationId: '123_test_@#$%_special_tags'
responses:
'200':
description: successful operation
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/csharp/OpenAPIClient/README.md
Expand Up @@ -106,6 +106,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **PATCH** /fake | To test \"client\" model
*FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters
*FakeApi* | [**TestGroupParameters**](docs/FakeApi.md#testgroupparameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
*FakeApi* | [**TestInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
*FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **GET** /fake/jsonFormData | test json serialization of form data
*FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **PATCH** /fake_classname_test | To test class name in snake case
Expand Down
65 changes: 65 additions & 0 deletions samples/client/petstore/csharp/OpenAPIClient/docs/FakeApi.md
Expand Up @@ -13,6 +13,7 @@ Method | HTTP request | Description
[**TestClientModel**](FakeApi.md#testclientmodel) | **PATCH** /fake | To test \&quot;client\&quot; model
[**TestEndpointParameters**](FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
[**TestEnumParameters**](FakeApi.md#testenumparameters) | **GET** /fake | To test enum parameters
[**TestGroupParameters**](FakeApi.md#testgroupparameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
[**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 @@ -600,6 +601,70 @@ 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)

<a name="testgroupparameters"></a>
# **TestGroupParameters**
> void TestGroupParameters (int? stringGroup = null, bool? booleanGroup = null, long? int64Group = null)
Fake endpoint to test group parameters (optional)

Fake endpoint to test group parameters (optional)

### Example
```csharp
using System;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;

namespace Example
{
public class TestGroupParametersExample
{
public void main()
{
var apiInstance = new FakeApi();
var stringGroup = 56; // int? | String in group parameters (optional)
var booleanGroup = true; // bool? | Boolean in group parameters (optional)
var int64Group = 789; // long? | Integer in group parameters (optional)
try
{
// Fake endpoint to test group parameters (optional)
apiInstance.TestGroupParameters(stringGroup, booleanGroup, int64Group);
}
catch (Exception e)
{
Debug.Print("Exception when calling FakeApi.TestGroupParameters: " + e.Message );
}
}
}
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**stringGroup** | **int?**| String in group parameters | [optional]
**booleanGroup** | **bool?**| Boolean in group parameters | [optional]
**int64Group** | **long?**| Integer in group parameters | [optional]

### Return type

void (empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **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)

<a name="testinlineadditionalproperties"></a>
# **TestInlineAdditionalProperties**
> void TestInlineAdditionalProperties (Dictionary<string, string> requestBody)
Expand Down

0 comments on commit aced89f

Please sign in to comment.