From 3a26e04433b4a6452bbb57537b5e8dff841a44b3 Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Thu, 24 Jan 2019 06:49:23 -0500 Subject: [PATCH 1/2] refactored php handlebars templates. --- .../handlebars/php/ObjectSerializer.mustache | 4 +- .../resources/handlebars/php/README.mustache | 44 ++-- .../resources/handlebars/php/api.mustache | 211 +++++++++--------- .../resources/handlebars/php/api_doc.mustache | 24 +- .../resources/handlebars/php/model.mustache | 6 +- .../handlebars/php/model_generic.mustache | 128 +++-------- .../handlebars/php/partial_header.mustache | 12 +- 7 files changed, 185 insertions(+), 244 deletions(-) diff --git a/src/main/resources/handlebars/php/ObjectSerializer.mustache b/src/main/resources/handlebars/php/ObjectSerializer.mustache index 11ef4c3b53..460b69b705 100644 --- a/src/main/resources/handlebars/php/ObjectSerializer.mustache +++ b/src/main/resources/handlebars/php/ObjectSerializer.mustache @@ -261,7 +261,7 @@ class ObjectSerializer // determine file name if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) { - $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . self::sanitizeFilename($match[1]); + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]); } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } @@ -283,7 +283,7 @@ class ObjectSerializer // If a discriminator is defined and points to a valid subclass, use it. $discriminator = $class::DISCRIMINATOR; if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { - $subclass = '{{backslash}}{{invokerPackage}}\Model\\' . $data->{$discriminator}; + $subclass = '\{{invokerPackage}}\Model\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { $class = $subclass; } diff --git a/src/main/resources/handlebars/php/README.mustache b/src/main/resources/handlebars/php/README.mustache index 3670ea1ad4..349b8185c1 100644 --- a/src/main/resources/handlebars/php/README.mustache +++ b/src/main/resources/handlebars/php/README.mustache @@ -1,5 +1,7 @@ # {{packagePath}} -{{#appDescription}}{{{appDescription}}}{{/appDescription}} +{{#appDescription}} +{{{appDescription}}} +{{/appDescription}} This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: @@ -64,29 +66,30 @@ Please follow the [installation procedure](#installation--usage) and then run th ```php setUsername('YOUR_USERNAME') - ->setPassword('YOUR_PASSWORD');{{/is}}{{#is this 'api-key'}} + ->setPassword('YOUR_PASSWORD');{{/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');{{/is}}{{#is this 'oauth'}} +// $config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');{{/isApiKey}}{{#isOAuth}} // Configure OAuth2 access token for authorization: {{{name}}} -$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/is}}{{/authMethods}} -{{/has}} +$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}} +{{/hasAuthMethods}} $apiInstance = new {{concat apiPackage '\\' 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(){{#has ../this 'auth-methods'}}, - $config{{/has}} + new GuzzleHttp\Client(){{#hasAuthMethods}}, + $config{{/hasAuthMethods}} ); {{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} {{/allParams}} try { - {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}});{{#returnType}} + {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} print_r($result);{{/returnType}} } catch (Exception $e) { echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL; @@ -115,25 +118,24 @@ Class | Method | HTTP request | Description {{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} {{#authMethods}}## {{{name}}} -{{#is this 'api-key'}}- **Type**: API key +{{#isApiKey}}- **Type**: API key - **API key parameter name**: {{{keyParamName}}} -- **Location**: {{#is this 'key-in-query'}}URL query string{{/is}}{{#is this 'key-in-header'}}HTTP header{{/is}} -{{/is}} -{{#is this 'basic'}}- **Type**: HTTP basic authentication -{{/is}} -{{#is this 'oauth'}}- **Type**: OAuth +- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} +{{/isApiKey}} +{{#isBasic}}- **Type**: HTTP basic authentication +{{/isBasic}} +{{#isOAuth}}- **Type**: OAuth - **Flow**: {{{flow}}} - **Authorization URL**: {{{authorizationUrl}}} - **Scopes**: {{^scopes}}N/A{{/scopes}} - -{{#each scopes}} - **{{{@key}}}**: {{this}} -{{/each}} -{{/is}} +{{#scopes}} - **{{{scope}}}**: {{{description}}} +{{/scopes}} +{{/isOAuth}} {{/authMethods}} ## Author -{{#apiInfo}}{{#apis}}{{#has ../../../this 'more'}}{{infoEmail}} -{{/has}}{{/apis}}{{/apiInfo}} +{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}} +{{/hasMore}}{{/apis}}{{/apiInfo}} diff --git a/src/main/resources/handlebars/php/api.mustache b/src/main/resources/handlebars/php/api.mustache index d57ce12178..10afa2857c 100644 --- a/src/main/resources/handlebars/php/api.mustache +++ b/src/main/resources/handlebars/php/api.mustache @@ -76,55 +76,56 @@ use {{invokerPackage}}\ObjectSerializer; { return $this->config; } + {{#operation}} /** * Operation {{{operationId}}} - {{#summary~}} +{{#summary}} * * {{{summary}}} - {{/summary~}} +{{/summary}} * - {{#description}} +{{#description}} * {{.}} * - {{/description~}} - {{#allParams~}} +{{/description}} +{{#allParams}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} - {{/allParams~}} +{{/allParams}} * * @throws {{backSlash}}{{invokerPackage}}\ApiException on non-2xx response * @throws \InvalidArgumentException * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#has this 'more'}}, {{/has}}{{/allParams}}) + public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}});{{#returnType}} + {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} return $response;{{/returnType}} } /** * Operation {{{operationId}}}WithHttpInfo - {{#summary~}} +{{#summary}} * * {{{summary}}} - {{/summary~}} +{{/summary}} * - {{#description}} +{{#description}} * {{.}} * - {{/description~}} - {{#allParams~}} +{{/description}} +{{#allParams}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} - {{/allParams~}} +{{/allParams}} * * @throws {{backSlash}}{{invokerPackage}}\ApiException on non-2xx response * @throws \InvalidArgumentException * @return array of {{#returnType}}{{{returnType}}}{{/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}}{{#has this 'more'}}, {{/has}}{{/allParams}}) + public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { $returnType = '{{returnType}}'; - $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}); + $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); try { $options = $this->createHttpClientOption(); @@ -154,7 +155,7 @@ use {{invokerPackage}}\ObjectSerializer; ); } - {{#returnType~}} + {{#returnType}} $responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer @@ -170,30 +171,25 @@ use {{invokerPackage}}\ObjectSerializer; $response->getStatusCode(), $response->getHeaders() ]; - {{/returnType~}} - {{^returnType}}return [null, $statusCode, $response->getHeaders()];{{/returnType~}} + {{/returnType}} + {{^returnType}} + return [null, $statusCode, $response->getHeaders()]; + {{/returnType}} } catch (ApiException $e) { - $returnType = '{{dataType}}'; - $content = $e->getResponseBody(); - if ($returnType !== '\SplFileObject') { - if (!in_array($returnType, ['string','integer','bool'])) { - $content = json_decode($content); - } - } switch ($e->getCode()) { - {{#responses~}} - {{#dataType~}} - {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard~}} + {{#responses}} + {{#dataType}} + {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}} $data = ObjectSerializer::deserialize( - $content, + $e->getResponseBody(), '{{dataType}}', $e->getResponseHeaders() ); $e->setResponseObject($data); break; - {{/dataType~}} - {{/responses~}} + {{/dataType}} + {{/responses}} } throw $e; } @@ -202,22 +198,22 @@ use {{invokerPackage}}\ObjectSerializer; /** * Operation {{{operationId}}}Async * - * {{{summary}~}} + * {{{summary}}} * - {{#description}} +{{#description}} * {{.}} * - {{/description~}} - {{#allParams~}} +{{/description}} +{{#allParams}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} - {{/allParams~}} +{{/allParams}} * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function {{operationId}}Async({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#has this 'more'}}, {{/has}}{{/allParams}}) + public function {{operationId}}Async({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - return $this->{{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}) + return $this->{{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ->then( function ($response) { return $response[0]; @@ -230,27 +226,27 @@ use {{invokerPackage}}\ObjectSerializer; * * {{{summary}}} * - {{#description}} +{{#description}} * {{.}} * - {{/description~}} - {{#allParams~}} +{{/description}} +{{#allParams}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} - {{/allParams~}} +{{/allParams}} * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function {{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#has this 'more'}}, {{/has}}{{/allParams}}) + public function {{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { $returnType = '{{returnType}}'; - $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}); + $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { - {{#returnType~}} + {{#returnType}} $responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer @@ -266,10 +262,10 @@ use {{invokerPackage}}\ObjectSerializer; $response->getStatusCode(), $response->getHeaders() ]; - {{/returnType~}} - {{^returnType~}} + {{/returnType}} + {{^returnType}} return [null, $response->getStatusCode(), $response->getHeaders()]; - {{/returnType~}} + {{/returnType}} }, function ($exception) { $response = $exception->getResponse(); @@ -291,63 +287,63 @@ use {{invokerPackage}}\ObjectSerializer; /** * Create request for operation '{{{operationId}}}' * - {{#allParams~}} +{{#allParams}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} - {{/allParams~}} +{{/allParams}} * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - protected function {{operationId}}Request({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#has this 'more'}}, {{/has}}{{/allParams}}) + protected function {{operationId}}Request({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - {{#allParams~}} - {{#required~}} + {{#allParams}} + {{#required}} // verify the required parameter '{{paramName}}' is set - if (${{paramName}} === null) { + if (${{paramName}} === null || (is_array(${{paramName}}) && count(${{paramName}}) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter ${{paramName}} when calling {{operationId}}' ); } - {{/required~}} - {{#has this 'validation'~}} - {{#maxLength~}} + {{/required}} + {{#hasValidation}} + {{#maxLength}} if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) > {{maxLength}}) { throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); } - {{/maxLength~}} - {{#minLength~}} + {{/maxLength}} + {{#minLength}} if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) < {{minLength}}) { throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); } - {{/minLength~}} - {{#maximum~}} + {{/minLength}} + {{#maximum}} if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.'); } - {{/maximum~}} - {{#minimum~}} + {{/maximum}} + {{#minimum}} if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.'); } - {{/minimum~}} - {{#pattern~}} + {{/minimum}} + {{#pattern}} if ({{^required}}${{paramName}} !== null && {{/required}}!preg_match("{{{pattern}}}", ${{paramName}})) { throw new \InvalidArgumentException("invalid value for \"{{paramName}}\" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}."); } - {{/pattern~}} - {{#maxItems~}} + {{/pattern}} + {{#maxItems}} if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) > {{maxItems}}) { throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.'); } - {{/maxItems~}} - {{#minItems~}} + {{/maxItems}} + {{#minItems}} if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) < {{minItems}}) { throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.'); } - {{/minItems~}} + {{/minItems}} - {{/has~}} - {{/allParams~}} + {{/hasValidation}} + {{/allParams}} $resourcePath = '{{{path}}}'; $formParams = []; @@ -356,36 +352,36 @@ use {{invokerPackage}}\ObjectSerializer; $httpBody = ''; $multipart = false; - {{#queryParams~}} + {{#queryParams}} // query params - {{#collectionFormat~}} + {{#collectionFormat}} if (is_array(${{paramName}})) { ${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{collectionFormat}}', true); } - {{/collectionFormat~}} + {{/collectionFormat}} if (${{paramName}} !== null) { $queryParams['{{baseName}}'] = ObjectSerializer::toQueryValue(${{paramName}}); } - {{/queryParams~}} - {{#headerParams~}} + {{/queryParams}} + {{#headerParams}} // header params - {{#collectionFormat~}} + {{#collectionFormat}} if (is_array(${{paramName}})) { ${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{collectionFormat}}'); } - {{/collectionFormat~}} + {{/collectionFormat}} if (${{paramName}} !== null) { $headerParams['{{baseName}}'] = ObjectSerializer::toHeaderValue(${{paramName}}); } - {{/headerParams~}} + {{/headerParams}} - {{#pathParams~}} + {{#pathParams}} // path params - {{#collectionFormat~}} + {{#collectionFormat}} if (is_array(${{paramName}})) { ${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{collectionFormat}}'); } - {{/collectionFormat~}} + {{/collectionFormat}} if (${{paramName}} !== null) { $resourcePath = str_replace( '{' . '{{baseName}}' . '}', @@ -393,36 +389,36 @@ use {{invokerPackage}}\ObjectSerializer; $resourcePath ); } - {{/pathParams~}} + {{/pathParams}} - {{#formParams~}} + {{#formParams}} // form params if (${{paramName}} !== null) { - {{#is this 'file'}} + {{#isFile}} $multipart = true; $formParams['{{baseName}}'] = \GuzzleHttp\Psr7\try_fopen(ObjectSerializer::toFormValue(${{paramName}}), 'rb'); - {{/is}} - {{#isNot this 'file'}} + {{/isFile}} + {{^isFile}} $formParams['{{baseName}}'] = ObjectSerializer::toFormValue(${{paramName}}); - {{/isNot}} + {{/isFile}} } - {{/formParams~}} + {{/formParams}} // body params $_tempBody = null; - {{#bodyParams~}} + {{#bodyParams}} if (isset(${{paramName}})) { $_tempBody = ${{paramName}}; } - {{/bodyParams~}} + {{/bodyParams}} if ($multipart) { $headers = $this->headerSelector->selectHeadersForMultipart( - [{{#produces}}'{{{mediaType}}}'{{#has ../this 'more'}}, {{/has}}{{/produces}}] + [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] ); } else { $headers = $this->headerSelector->selectHeaders( - [{{#produces}}'{{{mediaType}}}'{{#has ../this 'more'}}, {{/has}}{{/produces}}], - [{{#consumes}}'{{{mediaType}}}'{{#has ../this 'more'}}, {{/has}}{{/consumes}}] + [{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}], + [{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] ); } @@ -454,27 +450,28 @@ use {{invokerPackage}}\ObjectSerializer; $httpBody = \GuzzleHttp\Psr7\build_query($formParams); } } - {{#authMethods~}} - {{#is this 'api-key'~}} + + {{#authMethods}} + {{#isApiKey}} // this endpoint requires API key authentication $apiKey = $this->config->getApiKeyWithPrefix('{{keyParamName}}'); if ($apiKey !== null) { - {{#is this 'key-in-header'}}$headers['{{keyParamName}}'] = $apiKey;{{/is}}{{#is this 'key-in-query'}}$queryParams['{{keyParamName}}'] = $apiKey;{{/is}} + {{#isKeyInHeader}}$headers['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} } - {{/is~}} - {{#is this 'basic'~}} + {{/isApiKey}} + {{#isBasic}} // 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()); } - {{/is}} - {{#is this 'oauth'~}} + {{/isBasic}} + {{#isOAuth}} // this endpoint requires OAuth (access token) if ($this->config->getAccessToken() !== null) { $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); } - {{/is}} - {{/authMethods~}} + {{/isOAuth}} + {{/authMethods}} $defaultHeaders = []; if ($this->config->getUserAgent()) { @@ -496,7 +493,7 @@ use {{invokerPackage}}\ObjectSerializer; ); } - {{/operation~}} + {{/operation}} /** * Create http client option * @@ -516,4 +513,4 @@ use {{invokerPackage}}\ObjectSerializer; return $options; } } -{{/operations~}} +{{/operations}} diff --git a/src/main/resources/handlebars/php/api_doc.mustache b/src/main/resources/handlebars/php/api_doc.mustache index f836ed72d0..dbb1be0f6d 100644 --- a/src/main/resources/handlebars/php/api_doc.mustache +++ b/src/main/resources/handlebars/php/api_doc.mustache @@ -11,7 +11,7 @@ Method | HTTP request | Description {{#operations}} {{#operation}} # **{{{operationId}}}** -> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}) +> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {{{summary}}}{{#notes}} @@ -21,31 +21,31 @@ Method | HTTP request | Description ```php setUsername('YOUR_USERNAME') ->setPassword('YOUR_PASSWORD'); -{{/is}}{{#is this 'api-key'}} +{{/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');{{/is}}{{#is this 'oauth'}} +// $config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');{{/isApiKey}}{{#isOAuth}} // Configure OAuth2 access token for authorization: {{{name}}} -$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/is}}{{/authMethods}} -{{/has}} +$config = {{{invokerPackage}}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}} +{{/hasAuthMethods}} $apiInstance = new {{concat apiPackage '\\' 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(){{#has this 'auth-methods'}}, - $config{{/has}} + new GuzzleHttp\Client(){{#hasAuthMethods}}, + $config{{/hasAuthMethods}} ); {{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} {{/allParams}} try { - {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}});{{#returnType}} + {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} print_r($result);{{/returnType}} } catch (Exception $e) { echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL; @@ -57,7 +57,7 @@ try { {{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#@last}} Name | Type | Description | Notes ------------- | ------------- | ------------- | -------------{{/@last}}{{/allParams}} -{{#allParams}} **{{paramName}}** | {{#is this 'file'}}**{{dataType}}**{{/is}}{{#is this 'primitive-type'}}**{{dataType}}**{{/is}}{{#isNot this 'primitive-type'}}{{#isNot this 'file'}}[**{{dataType}}**](../Model/{{baseType}}.md){{/isNot}}{{/isNot}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}} +{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**](../Model/{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}} {{/allParams}} ### Return type @@ -70,8 +70,8 @@ Name | Type | Description | Notes ### HTTP request headers - - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#has ../this 'more'}}, {{/has}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} - - **Accept**: {{#produces}}{{{mediaType}}}{{#has ../this 'more'}}, {{/has}}{{/produces}}{{^produces}}Not defined{{/produces}} + - **Content-Type**: {{#consumes}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} + - **Accept**: {{#produces}}{{{mediaType}}}{{#hasMore}}, {{/hasMore}}{{/produces}}{{^produces}}Not defined{{/produces}} [[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/src/main/resources/handlebars/php/model.mustache b/src/main/resources/handlebars/php/model.mustache index c5d844628e..30b12efe9a 100644 --- a/src/main/resources/handlebars/php/model.mustache +++ b/src/main/resources/handlebars/php/model.mustache @@ -20,12 +20,12 @@ */ namespace {{modelPackage}}; -{{#isNot this 'enum'}} +{{^isEnum}} {{^parentSchema}} use \ArrayAccess; {{/parentSchema}} -{{/isNot}} +{{/isEnum}} use {{backSlash}}{{invokerPackage}}\ObjectSerializer; /** @@ -39,5 +39,5 @@ use {{backSlash}}{{invokerPackage}}\ObjectSerializer; * @author Swagger Codegen team * @link https://github.com/swagger-api/swagger-codegen */ -{{#is this 'enum'}}{{>model_enum}}{{/is}}{{#isNot this 'enum'}}{{>model_generic}}{{/isNot}} +{{#isEnum}}{{>model_enum}}{{/isEnum}}{{^isEnum}}{{>model_generic}}{{/isEnum}} {{/model}}{{/models}} diff --git a/src/main/resources/handlebars/php/model_generic.mustache b/src/main/resources/handlebars/php/model_generic.mustache index db0eb96722..750b4e9638 100644 --- a/src/main/resources/handlebars/php/model_generic.mustache +++ b/src/main/resources/handlebars/php/model_generic.mustache @@ -15,8 +15,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa * @var string[] */ protected static $swaggerTypes = [ - {{#vars}}'{{name}}' => '{{{datatype}}}'{{#has this 'more'}}, - {{/has}}{{/vars}} + {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} ]; /** @@ -25,8 +25,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa * @var string[] */ protected static $swaggerFormats = [ - {{#vars}}'{{name}}' => {{#dataFormat}}'{{{dataFormat}}}'{{/dataFormat}}{{^dataFormat}}null{{/dataFormat}}{{#has this 'more'}}, - {{/has}}{{/vars}} + {{#vars}}'{{name}}' => {{#dataFormat}}'{{{dataFormat}}}'{{/dataFormat}}{{^dataFormat}}null{{/dataFormat}}{{#hasMore}}, + {{/hasMore}}{{/vars}} ]; /** @@ -56,8 +56,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa * @var string[] */ protected static $attributeMap = [ - {{#vars}}'{{name}}' => '{{baseName}}'{{#has this 'more'}}, - {{/has}}{{/vars}} + {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} ]; /** @@ -66,8 +66,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa * @var string[] */ protected static $setters = [ - {{#vars}}'{{name}}' => '{{setter}}'{{#has this 'more'}}, - {{/has}}{{/vars}} + {{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} ]; /** @@ -76,8 +76,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa * @var string[] */ protected static $getters = [ - {{#vars}}'{{name}}' => '{{getter}}'{{#has this 'more'}}, - {{/has}}{{/vars}} + {{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} ]; /** @@ -121,10 +121,10 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa return self::$swaggerModelName; } - {{#vars}}{{#is this 'enum'}}{{#allowableValues}}{{#enumVars}}const {{enumName}}_{{{name}}} = {{{value}}}; - {{/enumVars}}{{/allowableValues}}{{/is}}{{/vars}} + {{#vars}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}const {{enumName}}_{{{name}}} = {{{value}}}; + {{/enumVars}}{{/allowableValues}}{{/isEnum}}{{/vars}} - {{#vars}}{{#is this 'enum'}} + {{#vars}}{{#isEnum}} /** * Gets allowable values of the enum * @@ -137,7 +137,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa {{/@last}}{{/enumVars}}{{/allowableValues}} ]; } - {{/is}}{{/vars}} + {{/isEnum}}{{/vars}} {{^parentSchema}} /** @@ -191,27 +191,27 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa $invalidProperties[] = "'{{name}}' can't be null"; } {{/required}} - {{#is this 'enum'}} - {{#isNot this 'container'}} + {{#isEnum}} + {{^isContainer}} $allowedValues = $this->{{getter}}AllowableValues(); - if (!in_array($this->container['{{name}}'], $allowedValues)) { + if (!is_null($this->container['{{name}}']) && !in_array($this->container['{{name}}'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for '{{name}}', must be one of '%s'", implode("', '", $allowedValues) ); } - {{/isNot}} - {{/is}} - {{#has this 'validation'}} + {{/isContainer}} + {{/isEnum}} + {{#hasValidation}} {{#maxLength}} - if ({{^required}}!is_null($this->container['{{name}}']) && {{/required}}(strlen($this->container['{{name}}']) > {{maxLength}})) { + if ({{^required}}!is_null($this->container['{{name}}']) && {{/required}}(mb_strlen($this->container['{{name}}']) > {{maxLength}})) { $invalidProperties[] = "invalid value for '{{name}}', the character length must be smaller than or equal to {{{maxLength}}}."; } {{/maxLength}} {{#minLength}} - if ({{^required}}!is_null($this->container['{{name}}']) && {{/required}}(strlen($this->container['{{name}}']) < {{minLength}})) { + if ({{^required}}!is_null($this->container['{{name}}']) && {{/required}}(mb_strlen($this->container['{{name}}']) < {{minLength}})) { $invalidProperties[] = "invalid value for '{{name}}', the character length must be bigger than or equal to {{{minLength}}}."; } @@ -246,7 +246,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa } {{/minItems}} - {{/has}} + {{/hasValidation}} {{/vars}} return $invalidProperties; } @@ -259,65 +259,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa */ public function valid() { - {{#parent}} - if (!parent::valid()) { - return false; - } - {{/parent}} - - {{#vars}} - {{#required}} - if ($this->container['{{name}}'] === null) { - return false; - } - {{/required}} - {{#is this 'enum'}} - {{#isNot this 'container'}} - $allowedValues = $this->{{getter}}AllowableValues(); - if (!in_array($this->container['{{name}}'], $allowedValues)) { - return false; - } - {{/isNot}} - {{/is}} - {{#hasValidation}} - {{#maxLength}} - if (strlen($this->container['{{name}}']) > {{maxLength}}) { - return false; - } - {{/maxLength}} - {{#minLength}} - if (strlen($this->container['{{name}}']) < {{minLength}}) { - return false; - } - {{/minLength}} - {{#maximum}} - if ($this->container['{{name}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) { - return false; - } - {{/maximum}} - {{#minimum}} - if ($this->container['{{name}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) { - return false; - } - {{/minimum}} - {{#pattern}} - if (!preg_match("{{{pattern}}}", $this->container['{{name}}'])) { - return false; - } - {{/pattern}} - {{#maxItems}} - if (count($this->container['{{name}}']) > {{maxItems}}) { - return false; - } - {{/maxItems}} - {{#minItems}} - if (count($this->container['{{name}}']) < {{minItems}}) { - return false; - } - {{/minItems}} - {{/hasValidation}} - {{/vars}} - return true; + return count($this->listInvalidProperties()) === 0; } {{#vars}} @@ -341,10 +283,10 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa */ public function {{setter}}(${{name}}) { - {{#is this 'enum'}} + {{#isEnum}} $allowedValues = $this->{{getter}}AllowableValues(); - {{#isNot this 'container'}} - if ({{^required}}!is_null(${{name}}) && {{/required}}!in_array(${{{name}}}, $allowedValues)) { + {{^isContainer}} + if ({{^required}}!is_null(${{name}}) && {{/required}}!in_array(${{{name}}}, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for '{{name}}', must be one of '%s'", @@ -352,8 +294,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa ) ); } - {{/isNot}} - {{#is this 'container'}} + {{/isContainer}} + {{#isContainer}} if ({{^required}}!is_null(${{name}}) && {{/required}}array_diff(${{{name}}}, $allowedValues)) { throw new \InvalidArgumentException( sprintf( @@ -362,15 +304,15 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa ) ); } - {{/is}} - {{/is}} - {{#has this 'validation'}} + {{/isContainer}} + {{/isEnum}} + {{#hasValidation}} {{#maxLength}} - if ({{^required}}!is_null(${{name}}) && {{/required}}(strlen(${{name}}) > {{maxLength}})) { + if ({{^required}}!is_null(${{name}}) && {{/required}}(mb_strlen(${{name}}) > {{maxLength}})) { throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); }{{/maxLength}} {{#minLength}} - if ({{^required}}!is_null(${{name}}) && {{/required}}(strlen(${{name}}) < {{minLength}})) { + if ({{^required}}!is_null(${{name}}) && {{/required}}(mb_strlen(${{name}}) < {{minLength}})) { throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); } {{/minLength}} @@ -398,7 +340,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.'); } {{/minItems}} - {{/has}} + {{/hasValidation}} $this->container['{{name}}'] = ${{name}}; return $this; diff --git a/src/main/resources/handlebars/php/partial_header.mustache b/src/main/resources/handlebars/php/partial_header.mustache index 090d2acee9..4cf2337cac 100644 --- a/src/main/resources/handlebars/php/partial_header.mustache +++ b/src/main/resources/handlebars/php/partial_header.mustache @@ -1,12 +1,12 @@ /** - {{#appName~}} - * {{{appName}~}} + {{#appName}} + * {{{appName}}} * - {{/appName~}} - {{#appDescription~}} - * {{{appDescription}~}} + {{/appName}} + {{#appDescription}} + * {{{appDescription}}} * - {{/appDescription~}} + {{/appDescription}} * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} * Generated by: https://github.com/swagger-api/swagger-codegen.git From a0e439471f030a2c6487fc0c255a5dc5616a96d8 Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Thu, 24 Jan 2019 22:59:31 -0500 Subject: [PATCH 2/2] added `contents`element to api templates. --- .../resources/handlebars/php/README.mustache | 10 ++--- .../resources/handlebars/php/api.mustache | 44 ++++++++++--------- .../resources/handlebars/php/api_doc.mustache | 18 ++++---- .../resources/mustache/php/README.mustache | 10 ++--- src/main/resources/mustache/php/api.mustache | 44 ++++++++++--------- .../resources/mustache/php/api_doc.mustache | 18 ++++---- 6 files changed, 76 insertions(+), 68 deletions(-) diff --git a/src/main/resources/handlebars/php/README.mustache b/src/main/resources/handlebars/php/README.mustache index 349b8185c1..955eed2c67 100644 --- a/src/main/resources/handlebars/php/README.mustache +++ b/src/main/resources/handlebars/php/README.mustache @@ -66,7 +66,7 @@ Please follow the [installation procedure](#installation--usage) and then run th ```php setUsername('YOUR_USERNAME') @@ -85,16 +85,16 @@ $apiInstance = new {{concat apiPackage '\\' classname}}( new GuzzleHttp\Client(){{#hasAuthMethods}}, $config{{/hasAuthMethods}} ); -{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} -{{/allParams}} +{{#parameters}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} +{{/parameters}} try { - {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}} print_r($result);{{/returnType}} } catch (Exception $e) { echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL; } -{{/@first}}{{/operation}}{{/operations}}{{/@first}}{{/apis}}{{/apiInfo}} +{{/@first}}{{/contents}}{{/operation}}{{/operations}}{{/@first}}{{/apis}}{{/apiInfo}} ?> ``` diff --git a/src/main/resources/handlebars/php/api.mustache b/src/main/resources/handlebars/php/api.mustache index 10afa2857c..d7e89f4000 100644 --- a/src/main/resources/handlebars/php/api.mustache +++ b/src/main/resources/handlebars/php/api.mustache @@ -78,6 +78,7 @@ use {{invokerPackage}}\ObjectSerializer; } {{#operation}} +{{#contents}} /** * Operation {{{operationId}}} {{#summary}} @@ -89,17 +90,17 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @throws {{backSlash}}{{invokerPackage}}\ApiException on non-2xx response * @throws \InvalidArgumentException * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { - {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}} return $response;{{/returnType}} } @@ -114,18 +115,18 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @throws {{backSlash}}{{invokerPackage}}\ApiException on non-2xx response * @throws \InvalidArgumentException * @return array of {{#returnType}}{{{returnType}}}{{/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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { $returnType = '{{returnType}}'; - $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + $request = $this->{{operationId}}Request({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}); try { $options = $this->createHttpClientOption(); @@ -204,16 +205,16 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { - return $this->{{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + return $this->{{operationId}}AsyncWithHttpInfo({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) ->then( function ($response) { return $response[0]; @@ -230,17 +231,17 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { $returnType = '{{returnType}}'; - $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + $request = $this->{{operationId}}Request({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -287,16 +288,16 @@ use {{invokerPackage}}\ObjectSerializer; /** * Create request for operation '{{{operationId}}}' * -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { - {{#allParams}} + {{#parameters}} {{#required}} // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null || (is_array(${{paramName}}) && count(${{paramName}}) === 0)) { @@ -343,7 +344,7 @@ use {{invokerPackage}}\ObjectSerializer; {{/minItems}} {{/hasValidation}} - {{/allParams}} + {{/parameters}} $resourcePath = '{{{path}}}'; $formParams = []; @@ -493,6 +494,7 @@ use {{invokerPackage}}\ObjectSerializer; ); } + {{/contents}} {{/operation}} /** * Create http client option diff --git a/src/main/resources/handlebars/php/api_doc.mustache b/src/main/resources/handlebars/php/api_doc.mustache index dbb1be0f6d..1780b676e8 100644 --- a/src/main/resources/handlebars/php/api_doc.mustache +++ b/src/main/resources/handlebars/php/api_doc.mustache @@ -10,8 +10,9 @@ Method | HTTP request | Description {{#operations}} {{#operation}} +{{#contents}} # **{{{operationId}}}** -> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) +> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) {{{summary}}}{{#notes}} @@ -41,11 +42,11 @@ $apiInstance = new {{concat apiPackage '\\' classname}}( new GuzzleHttp\Client(){{#hasAuthMethods}}, $config{{/hasAuthMethods}} ); -{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} -{{/allParams}} +{{#parameters}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} +{{/parameters}} try { - {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}} print_r($result);{{/returnType}} } catch (Exception $e) { echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL; @@ -54,11 +55,11 @@ try { ``` ### Parameters -{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#@last}} +{{^parameters}}This endpoint does not need any parameter.{{/parameters}}{{#parameters}}{{#@last}} Name | Type | Description | Notes -------------- | ------------- | ------------- | -------------{{/@last}}{{/allParams}} -{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**](../Model/{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}} -{{/allParams}} +------------- | ------------- | ------------- | -------------{{/@last}}{{/parameters}} +{{#parameters}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**](../Model/{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}} +{{/parameters}} ### Return type @@ -75,5 +76,6 @@ Name | Type | Description | Notes [[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) +{{/contents}} {{/operation}} {{/operations}} diff --git a/src/main/resources/mustache/php/README.mustache b/src/main/resources/mustache/php/README.mustache index e17247ef7a..8c8fb41055 100644 --- a/src/main/resources/mustache/php/README.mustache +++ b/src/main/resources/mustache/php/README.mustache @@ -66,7 +66,7 @@ Please follow the [installation procedure](#installation--usage) and then run th ```php setUsername('YOUR_USERNAME') @@ -85,16 +85,16 @@ $apiInstance = new {{invokerPackage}}\Api\{{classname}}( new GuzzleHttp\Client(){{#hasAuthMethods}}, $config{{/hasAuthMethods}} ); -{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} -{{/allParams}} +{{#parameters}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} +{{/parameters}} try { - {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}} print_r($result);{{/returnType}} } catch (Exception $e) { echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL; } -{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} +{{/-first}}{{/contents}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} ?> ``` diff --git a/src/main/resources/mustache/php/api.mustache b/src/main/resources/mustache/php/api.mustache index cf5064c94c..3087239331 100644 --- a/src/main/resources/mustache/php/api.mustache +++ b/src/main/resources/mustache/php/api.mustache @@ -78,6 +78,7 @@ use {{invokerPackage}}\ObjectSerializer; } {{#operation}} +{{#contents}} /** * Operation {{{operationId}}} {{#summary}} @@ -89,17 +90,17 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @throws \{{invokerPackage}}\ApiException on non-2xx response * @throws \InvalidArgumentException * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} */ - public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { - {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}} return $response;{{/returnType}} } @@ -114,18 +115,18 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @throws \{{invokerPackage}}\ApiException on non-2xx response * @throws \InvalidArgumentException * @return array of {{#returnType}}{{{returnType}}}{{/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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { $returnType = '{{returnType}}'; - $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + $request = $this->{{operationId}}Request({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}); try { $options = $this->createHttpClientOption(); @@ -204,16 +205,16 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { - return $this->{{operationId}}AsyncWithHttpInfo({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + return $this->{{operationId}}AsyncWithHttpInfo({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) ->then( function ($response) { return $response[0]; @@ -230,17 +231,17 @@ use {{invokerPackage}}\ObjectSerializer; * {{.}} * {{/description}} -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { $returnType = '{{returnType}}'; - $request = $this->{{operationId}}Request({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + $request = $this->{{operationId}}Request({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -287,16 +288,16 @@ use {{invokerPackage}}\ObjectSerializer; /** * Create request for operation '{{{operationId}}}' * -{{#allParams}} +{{#parameters}} * @param {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} -{{/allParams}} +{{/parameters}} * * @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({{#parameters}}${{paramName}}{{^required}} = {{#defaultValue}}'{{{.}}}'{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { - {{#allParams}} + {{#parameters}} {{#required}} // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null || (is_array(${{paramName}}) && count(${{paramName}}) === 0)) { @@ -343,7 +344,7 @@ use {{invokerPackage}}\ObjectSerializer; {{/minItems}} {{/hasValidation}} - {{/allParams}} + {{/parameters}} $resourcePath = '{{{path}}}'; $formParams = []; @@ -493,6 +494,7 @@ use {{invokerPackage}}\ObjectSerializer; ); } + {{/contents}} {{/operation}} /** * Create http client option diff --git a/src/main/resources/mustache/php/api_doc.mustache b/src/main/resources/mustache/php/api_doc.mustache index 4118b83c30..aa949603db 100644 --- a/src/main/resources/mustache/php/api_doc.mustache +++ b/src/main/resources/mustache/php/api_doc.mustache @@ -10,8 +10,9 @@ Method | HTTP request | Description {{#operations}} {{#operation}} +{{#contents}} # **{{{operationId}}}** -> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) +> {{#returnType}}{{{returnType}}} {{/returnType}}{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) {{{summary}}}{{#notes}} @@ -41,11 +42,11 @@ $apiInstance = new {{invokerPackage}}\Api\{{classname}}( new GuzzleHttp\Client(){{#hasAuthMethods}}, $config{{/hasAuthMethods}} ); -{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} -{{/allParams}} +{{#parameters}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{description}}} +{{/parameters}} try { - {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + {{#returnType}}$result = {{/returnType}}$apiInstance->{{{operationId}}}({{#parameters}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});{{#returnType}} print_r($result);{{/returnType}} } catch (Exception $e) { echo 'Exception when calling {{classname}}->{{operationId}}: ', $e->getMessage(), PHP_EOL; @@ -54,11 +55,11 @@ try { ``` ### Parameters -{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}} +{{^parameters}}This endpoint does not need any parameter.{{/parameters}}{{#parameters}}{{#-last}} Name | Type | Description | Notes -------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}} -{{#allParams}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**](../Model/{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}} -{{/allParams}} +------------- | ------------- | ------------- | -------------{{/-last}}{{/parameters}} +{{#parameters}} **{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**](../Model/{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}} +{{/parameters}} ### Return type @@ -75,5 +76,6 @@ Name | Type | Description | Notes [[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) +{{/contents}} {{/operation}} {{/operations}}