forked from loafle/openapi-generator-original
164 lines
5.7 KiB
Plaintext
164 lines
5.7 KiB
Plaintext
<?php
|
|
/**
|
|
* Copyright 2015 SmartBear Software
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/**
|
|
*
|
|
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
|
*/
|
|
|
|
namespace {{apiNamespace}};
|
|
|
|
use {{invokerNamespace}}\ApiConfiguration;
|
|
use {{invokerNamespace}}\ApiClient;
|
|
use {{invokerNamespace}}\ApiException;
|
|
use {{invokerNamespace}}\ObjectSerializer;
|
|
|
|
{{#imports}}
|
|
use {{{import}}};
|
|
{{/imports}}
|
|
|
|
{{#operations}}
|
|
class {{classname}} {
|
|
|
|
/** @var ApiClient */
|
|
private $apiClient;
|
|
|
|
function __construct($apiClient = null) {
|
|
if ($apiClient == null) {
|
|
$apiClient = (new ApiClient())->setHost('{{basePath}}');
|
|
}
|
|
|
|
$this->apiClient = $apiClient;
|
|
}
|
|
|
|
/**
|
|
* get the API client
|
|
* @return ApiClient this API's client
|
|
*/
|
|
public function getApiClient() {
|
|
return $this->apiClient;
|
|
}
|
|
|
|
/**
|
|
* set the API client
|
|
* @param ApiClient $apiClient
|
|
* @return {{classname}}
|
|
*/
|
|
public function setApiClient(ApiClient $apiClient) {
|
|
$this->apiClient = $apiClient;
|
|
return $this;
|
|
}
|
|
|
|
{{#operation}}
|
|
/**
|
|
* {{{nickname}}}
|
|
*
|
|
* {{{summary}}}
|
|
*
|
|
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
|
{{/allParams}} * @return {{#returnType}}{{#isListContainer}}{{returnBaseType}}[]{{/isListContainer}}{{^isListContainer}}{{{returnType}}}{{/isListContainer}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
|
* @throws \{{invokerNamespace}}\ApiException on non-2xx response
|
|
*/
|
|
public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
|
{{#allParams}}{{#required}}
|
|
// verify the required parameter '{{paramName}}' is set
|
|
if (${{paramName}} === null) {
|
|
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
|
|
}
|
|
{{/required}}{{/allParams}}
|
|
|
|
// parse inputs
|
|
$resourcePath = "{{path}}";
|
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
|
$method = "{{httpMethod}}";
|
|
$httpBody = '';
|
|
$queryParams = array();
|
|
$headerParams = array();
|
|
$formParams = array();
|
|
$_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
|
|
if (!is_null($_header_accept)) {
|
|
$headerParams['Accept'] = $_header_accept;
|
|
}
|
|
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
|
|
|
|
{{#queryParams}}// query params
|
|
if(${{paramName}} !== null) {
|
|
$queryParams['{{baseName}}'] = ObjectSerializer::toQueryValue(${{paramName}});
|
|
}{{/queryParams}}
|
|
{{#headerParams}}// header params
|
|
if(${{paramName}} !== null) {
|
|
$headerParams['{{baseName}}'] = ObjectSerializer::toHeaderValue(${{paramName}});
|
|
}{{/headerParams}}
|
|
{{#pathParams}}// path params
|
|
if(${{paramName}} !== null) {
|
|
$resourcePath = str_replace("{" . "{{baseName}}" . "}",
|
|
ObjectSerializer::toPathValue(${{paramName}}),
|
|
$resourcePath);
|
|
}{{/pathParams}}
|
|
{{#formParams}}// form params
|
|
if (${{paramName}} !== null) {
|
|
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}ObjectSerializer::toFormValue(${{paramName}});
|
|
}{{/formParams}}
|
|
{{#bodyParams}}// body params
|
|
$_tempBody = null;
|
|
if (isset(${{paramName}})) {
|
|
$_tempBody = ${{paramName}};
|
|
}{{/bodyParams}}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
|
} else if (count($formParams) > 0) {
|
|
// for HTTP post (form)
|
|
$httpBody = $formParams;
|
|
}
|
|
{{#authMethods}}{{#isApiKey}}
|
|
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
|
|
if (isset($apiKey)) {
|
|
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
|
|
}{{/isApiKey}}
|
|
{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
|
|
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
|
{{/authMethods}}
|
|
// make the API Call
|
|
try {
|
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
|
$queryParams, $httpBody,
|
|
$headerParams);
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
|
case {{code}}:
|
|
$data = ObjectSerializer::deserialize($e->getResponseBody(), '{{dataType}}');
|
|
$e->setResponseObject($data);
|
|
break;{{/dataType}}{{/responses}}
|
|
}
|
|
|
|
throw $e;
|
|
}
|
|
{{#returnType}}
|
|
if (!$response) {
|
|
return null;
|
|
}
|
|
|
|
$responseObject = ObjectSerializer::deserialize($response,'{{returnType}}');
|
|
return $responseObject;
|
|
{{/returnType}}
|
|
}
|
|
{{/operation}}
|
|
}
|
|
{{/operations}}
|