github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/php/api.mustache (about)

     1  <?php
     2  /**
     3   * {{classname}}
     4   * PHP version 5
     5   *
     6   * @category Class
     7   * @package  {{invokerPackage}}
     8   * @author   OpenAPI Generator team
     9   * @link     https://openapi-generator.tech
    10   */
    11  
    12  {{>partial_header}}
    13  /**
    14   * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
    15   * https://openapi-generator.tech
    16   * Do not edit the class manually.
    17   */
    18  
    19  namespace {{apiPackage}};
    20  
    21  use GuzzleHttp\Client;
    22  use GuzzleHttp\ClientInterface;
    23  use GuzzleHttp\Exception\RequestException;
    24  use GuzzleHttp\Psr7\MultipartStream;
    25  use GuzzleHttp\Psr7\Request;
    26  use GuzzleHttp\RequestOptions;
    27  use {{invokerPackage}}\ApiException;
    28  use {{invokerPackage}}\Configuration;
    29  use {{invokerPackage}}\HeaderSelector;
    30  use {{invokerPackage}}\ObjectSerializer;
    31  
    32  /**
    33   * {{classname}} Class Doc Comment
    34   *
    35   * @category Class
    36   * @package  {{invokerPackage}}
    37   * @author   OpenAPI Generator team
    38   * @link     https://openapi-generator.tech
    39   */
    40  {{#operations}}class {{classname}}
    41  {
    42      /**
    43       * @var ClientInterface
    44       */
    45      protected $client;
    46  
    47      /**
    48       * @var Configuration
    49       */
    50      protected $config;
    51  
    52      /**
    53       * @var HeaderSelector
    54       */
    55      protected $headerSelector;
    56  
    57      /**
    58       * @var int Host index
    59       */
    60      protected $hostIndex;
    61  
    62      /**
    63       * @param ClientInterface $client
    64       * @param Configuration   $config
    65       * @param HeaderSelector  $selector
    66       * @param int             $host_index (Optional) host index to select the list of hosts if defined in the OpenAPI spec
    67       */
    68      public function __construct(
    69          ClientInterface $client = null,
    70          Configuration $config = null,
    71          HeaderSelector $selector = null,
    72          $host_index = 0
    73      ) {
    74          $this->client = $client ?: new Client();
    75          $this->config = $config ?: new Configuration();
    76          $this->headerSelector = $selector ?: new HeaderSelector();
    77          $this->hostIndex = $host_index;
    78      }
    79  
    80      /**
    81       * Set the host index
    82       *
    83       * @param  int Host index (required)
    84       */
    85      public function setHostIndex($host_index)
    86      {
    87          $this->hostIndex = $host_index;
    88      }
    89  
    90      /**
    91       * Get the host index
    92       *
    93       * @return Host index
    94       */
    95      public function getHostIndex()
    96      {
    97          return $this->hostIndex;
    98      }
    99  
   100      /**
   101       * @return Configuration
   102       */
   103      public function getConfig()
   104      {
   105          return $this->config;
   106      }
   107  
   108  {{#operation}}
   109      /**
   110       * Operation {{{operationId}}}
   111  {{#summary}}
   112       *
   113       * {{{summary}}}
   114  {{/summary}}
   115       *
   116  {{#description}}
   117       * {{.}}
   118       *
   119  {{/description}}
   120  {{#vendorExtensions.x-group-parameters}}
   121       * Note: the input parameter is an associative array with the keys listed as the parameter name below
   122       *
   123  {{/vendorExtensions.x-group-parameters}}
   124  {{#servers}}
   125  {{#-first}}
   126       * This oepration contains host(s) defined in the OpenAP spec. Use 'hostIndex' to select the host.
   127  {{/-first}}
   128       * URL: {{{url}}}
   129  {{#-last}}
   130       *
   131  {{/-last}}
   132  {{/servers}}
   133  {{#allParams}}
   134       * @param  {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
   135  {{/allParams}}
   136       *
   137       * @throws \{{invokerPackage}}\ApiException on non-2xx response
   138       * @throws \InvalidArgumentException
   139       * @return {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}void{{/returnType}}
   140       */
   141      public function {{operationId}}({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
   142      {
   143          {{#returnType}}list($response) = {{/returnType}}$this->{{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});{{#returnType}}
   144          return $response;{{/returnType}}
   145      }
   146  
   147      /**
   148       * Operation {{{operationId}}}WithHttpInfo
   149  {{#summary}}
   150       *
   151       * {{{summary}}}
   152  {{/summary}}
   153       *
   154  {{#description}}
   155       * {{.}}
   156       *
   157  {{/description}}
   158  {{#vendorExtensions.x-group-parameters}}
   159       * Note: the input parameter is an associative array with the keys listed as the parameter name below
   160       *
   161  {{/vendorExtensions.x-group-parameters}}
   162  {{#servers}}
   163  {{#-first}}
   164       * This oepration contains host(s) defined in the OpenAP spec. Use 'hostIndex' to select the host.
   165  {{/-first}}
   166       * URL: {{{url}}}
   167  {{#-last}}
   168       *
   169  {{/-last}}
   170  {{/servers}}
   171  {{#allParams}}
   172       * @param  {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
   173  {{/allParams}}
   174       *
   175       * @throws \{{invokerPackage}}\ApiException on non-2xx response
   176       * @throws \InvalidArgumentException
   177       * @return array of {{#returnType}}{{#responses}}{{#dataType}}{{^-first}}|{{/-first}}{{/dataType}}{{{dataType}}}{{/responses}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings)
   178       */
   179      public function {{operationId}}WithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
   180      {
   181          $request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});
   182  
   183          try {
   184              $options = $this->createHttpClientOption();
   185              try {
   186                  $response = $this->client->send($request, $options);
   187              } catch (RequestException $e) {
   188                  throw new ApiException(
   189                      "[{$e->getCode()}] {$e->getMessage()}",
   190                      $e->getCode(),
   191                      $e->getResponse() ? $e->getResponse()->getHeaders() : null,
   192                      $e->getResponse() ? (string) $e->getResponse()->getBody() : null
   193                  );
   194              }
   195  
   196              $statusCode = $response->getStatusCode();
   197  
   198              if ($statusCode < 200 || $statusCode > 299) {
   199                  throw new ApiException(
   200                      sprintf(
   201                          '[%d] Error connecting to the API (%s)',
   202                          $statusCode,
   203                          $request->getUri()
   204                      ),
   205                      $statusCode,
   206                      $response->getHeaders(),
   207                      $response->getBody()
   208                  );
   209              }
   210              {{#returnType}}
   211          {{#responses}}
   212              {{#-first}}
   213  
   214              $responseBody = $response->getBody();
   215              switch($statusCode) {
   216              {{/-first}}
   217              {{#dataType}}
   218                  {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}}
   219                      if ('{{dataType}}' === '\SplFileObject') {
   220                          $content = $responseBody; //stream goes to serializer
   221                      } else {
   222                          $content = (string) $responseBody;
   223                      }
   224  
   225                      return [
   226                          ObjectSerializer::deserialize($content, '{{dataType}}', []),
   227                          $response->getStatusCode(),
   228                          $response->getHeaders()
   229                      ];
   230              {{/dataType}}
   231              {{#-last}}
   232              }
   233              {{/-last}}
   234          {{/responses}}
   235  
   236              $returnType = '{{returnType}}';
   237              $responseBody = $response->getBody();
   238              if ($returnType === '\SplFileObject') {
   239                  $content = $responseBody; //stream goes to serializer
   240              } else {
   241                  $content = (string) $responseBody;
   242              }
   243  
   244              return [
   245                  ObjectSerializer::deserialize($content, $returnType, []),
   246                  $response->getStatusCode(),
   247                  $response->getHeaders()
   248              ];
   249              {{/returnType}}
   250              {{^returnType}}
   251  
   252              return [null, $statusCode, $response->getHeaders()];
   253              {{/returnType}}
   254  
   255          } catch (ApiException $e) {
   256              switch ($e->getCode()) {
   257          {{#responses}}
   258              {{#dataType}}
   259                  {{^isWildcard}}case {{code}}:{{/isWildcard}}{{#isWildcard}}default:{{/isWildcard}}
   260                      $data = ObjectSerializer::deserialize(
   261                          $e->getResponseBody(),
   262                          '{{dataType}}',
   263                          $e->getResponseHeaders()
   264                      );
   265                      $e->setResponseObject($data);
   266                      break;
   267              {{/dataType}}
   268          {{/responses}}
   269              }
   270              throw $e;
   271          }
   272      }
   273  
   274      /**
   275       * Operation {{{operationId}}}Async
   276       *
   277       * {{{summary}}}
   278       *
   279  {{#description}}
   280       * {{.}}
   281       *
   282  {{/description}}
   283  {{#vendorExtensions.x-group-parameters}}
   284       * Note: the input parameter is an associative array with the keys listed as the parameter name below
   285       *
   286  {{/vendorExtensions.x-group-parameters}}
   287  {{#servers}}
   288  {{#-first}}
   289       * This oepration contains host(s) defined in the OpenAP spec. Use 'hostIndex' to select the host.
   290  {{/-first}}
   291       * URL: {{{url}}}
   292  {{#-last}}
   293       *
   294  {{/-last}}
   295  {{/servers}}
   296  {{#allParams}}
   297       * @param  {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
   298  {{/allParams}}
   299       *
   300       * @throws \InvalidArgumentException
   301       * @return \GuzzleHttp\Promise\PromiseInterface
   302       */
   303      public function {{operationId}}Async({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
   304      {
   305          return $this->{{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
   306              ->then(
   307                  function ($response) {
   308                      return $response[0];
   309                  }
   310              );
   311      }
   312  
   313      /**
   314       * Operation {{{operationId}}}AsyncWithHttpInfo
   315       *
   316       * {{{summary}}}
   317       *
   318  {{#description}}
   319       * {{.}}
   320       *
   321  {{/description}}
   322  {{#vendorExtensions.x-group-parameters}}
   323       * Note: the input parameter is an associative array with the keys listed as the parameter name below
   324       *
   325  {{/vendorExtensions.x-group-parameters}}
   326  {{#servers}}
   327  {{#-first}}
   328       * This oepration contains host(s) defined in the OpenAP spec. Use 'hostIndex' to select the host.
   329  {{/-first}}
   330       * URL: {{{url}}}
   331  {{#-last}}
   332       *
   333  {{/-last}}
   334  {{/servers}}
   335  {{#allParams}}
   336       * @param  {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
   337  {{/allParams}}
   338       *
   339       * @throws \InvalidArgumentException
   340       * @return \GuzzleHttp\Promise\PromiseInterface
   341       */
   342      public function {{operationId}}AsyncWithHttpInfo({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
   343      {
   344          $returnType = '{{returnType}}';
   345          $request = $this->{{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}});
   346  
   347          return $this->client
   348              ->sendAsync($request, $this->createHttpClientOption())
   349              ->then(
   350                  function ($response) use ($returnType) {
   351                      {{#returnType}}
   352                      $responseBody = $response->getBody();
   353                      if ($returnType === '\SplFileObject') {
   354                          $content = $responseBody; //stream goes to serializer
   355                      } else {
   356                          $content = (string) $responseBody;
   357                      }
   358  
   359                      return [
   360                          ObjectSerializer::deserialize($content, $returnType, []),
   361                          $response->getStatusCode(),
   362                          $response->getHeaders()
   363                      ];
   364                      {{/returnType}}
   365                      {{^returnType}}
   366                      return [null, $response->getStatusCode(), $response->getHeaders()];
   367                  {{/returnType}}
   368                  },
   369                  function ($exception) {
   370                      $response = $exception->getResponse();
   371                      $statusCode = $response->getStatusCode();
   372                      throw new ApiException(
   373                          sprintf(
   374                              '[%d] Error connecting to the API (%s)',
   375                              $statusCode,
   376                              $exception->getRequest()->getUri()
   377                          ),
   378                          $statusCode,
   379                          $response->getHeaders(),
   380                          $response->getBody()
   381                      );
   382                  }
   383              );
   384      }
   385  
   386      /**
   387       * Create request for operation '{{{operationId}}}'
   388       *
   389  {{#vendorExtensions.x-group-parameters}}
   390       * Note: the input parameter is an associative array with the keys listed as the parameter name below
   391       *
   392  {{/vendorExtensions.x-group-parameters}}
   393  {{#servers}}
   394  {{#-first}}
   395       * This oepration contains host(s) defined in the OpenAP spec. Use 'hostIndex' to select the host.
   396  {{/-first}}
   397       * URL: {{{url}}}
   398  {{#-last}}
   399       *
   400  {{/-last}}
   401  {{/servers}}
   402  {{#allParams}}
   403       * @param  {{dataType}} ${{paramName}}{{#description}} {{description}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
   404  {{/allParams}}
   405       *
   406       * @throws \InvalidArgumentException
   407       * @return \GuzzleHttp\Psr7\Request
   408       */
   409      protected function {{operationId}}Request({{^vendorExtensions.x-group-parameters}}{{#allParams}}${{paramName}}{{^required}} = {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}$associative_array{{/vendorExtensions.x-group-parameters}})
   410      {
   411          {{#vendorExtensions.x-group-parameters}}
   412          // unbox the parameters from the associative array
   413          {{#allParams}}
   414          ${{paramName}} = array_key_exists('{{paramName}}', $associative_array) ? $associative_array['{{paramName}}'] : {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}};
   415          {{/allParams}}
   416  
   417          {{/vendorExtensions.x-group-parameters}}
   418          {{#allParams}}
   419          {{#required}}
   420          // verify the required parameter '{{paramName}}' is set
   421          if (${{paramName}} === null || (is_array(${{paramName}}) && count(${{paramName}}) === 0)) {
   422              throw new \InvalidArgumentException(
   423                  'Missing the required parameter ${{paramName}} when calling {{operationId}}'
   424              );
   425          }
   426          {{/required}}
   427          {{#hasValidation}}
   428          {{#maxLength}}
   429          if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) > {{maxLength}}) {
   430              throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.');
   431          }
   432          {{/maxLength}}
   433          {{#minLength}}
   434          if ({{^required}}${{paramName}} !== null && {{/required}}strlen(${{paramName}}) < {{minLength}}) {
   435              throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.');
   436          }
   437          {{/minLength}}
   438          {{#maximum}}
   439          if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) {
   440              throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{maximum}}.');
   441          }
   442          {{/maximum}}
   443          {{#minimum}}
   444          if ({{^required}}${{paramName}} !== null && {{/required}}${{paramName}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) {
   445              throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{minimum}}.');
   446          }
   447          {{/minimum}}
   448          {{#pattern}}
   449          if ({{^required}}${{paramName}} !== null && {{/required}}!preg_match("{{{pattern}}}", ${{paramName}})) {
   450              throw new \InvalidArgumentException("invalid value for \"{{paramName}}\" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
   451          }
   452          {{/pattern}}
   453          {{#maxItems}}
   454          if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) > {{maxItems}}) {
   455              throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{maxItems}}.');
   456          }
   457          {{/maxItems}}
   458          {{#minItems}}
   459          if ({{^required}}${{paramName}} !== null && {{/required}}count(${{paramName}}) < {{minItems}}) {
   460              throw new \InvalidArgumentException('invalid value for "${{paramName}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{minItems}}.');
   461          }
   462          {{/minItems}}
   463  
   464          {{/hasValidation}}
   465          {{/allParams}}
   466  
   467          $resourcePath = '{{{path}}}';
   468          $formParams = [];
   469          $queryParams = [];
   470          $headerParams = [];
   471          $httpBody = '';
   472          $multipart = false;
   473  
   474          {{#queryParams}}
   475          // query params
   476          {{#isExplode}}
   477          if (${{paramName}} !== null) {
   478          {{#style}}
   479              if('form' === '{{style}}' && is_array(${{paramName}})) {
   480                  foreach(${{paramName}} as $key => $value) {
   481                      $queryParams[$key] = $value;
   482                  }
   483              }
   484              else {
   485                  $queryParams['{{baseName}}'] = ${{paramName}};
   486              }
   487          {{/style}}
   488          {{^style}}
   489              $queryParams['{{baseName}}'] = ${{paramName}};
   490          {{/style}}
   491          }
   492          {{/isExplode}}
   493          {{^isExplode}}
   494          if (is_array(${{paramName}})) {
   495              ${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{#style}}{{style}}{{/style}}{{^style}}{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}{{/style}}', true);
   496          }
   497          if (${{paramName}} !== null) {
   498              $queryParams['{{baseName}}'] = ${{paramName}};
   499          }
   500          {{/isExplode}}
   501          {{/queryParams}}
   502  
   503          {{#headerParams}}
   504          // header params
   505          {{#collectionFormat}}
   506          if (is_array(${{paramName}})) {
   507              ${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{collectionFormat}}');
   508          }
   509          {{/collectionFormat}}
   510          if (${{paramName}} !== null) {
   511              $headerParams['{{baseName}}'] = ObjectSerializer::toHeaderValue(${{paramName}});
   512          }
   513          {{/headerParams}}
   514  
   515          {{#pathParams}}
   516          // path params
   517          {{#collectionFormat}}
   518          if (is_array(${{paramName}})) {
   519              ${{paramName}} = ObjectSerializer::serializeCollection(${{paramName}}, '{{collectionFormat}}');
   520          }
   521          {{/collectionFormat}}
   522          if (${{paramName}} !== null) {
   523              $resourcePath = str_replace(
   524                  '{' . '{{baseName}}' . '}',
   525                  ObjectSerializer::toPathValue(${{paramName}}),
   526                  $resourcePath
   527              );
   528          }
   529          {{/pathParams}}
   530  
   531          {{#formParams}}
   532          // form params
   533          if (${{paramName}} !== null) {
   534              {{#isFile}}
   535              $multipart = true;
   536              $formParams['{{baseName}}'] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue(${{paramName}}), 'rb');
   537              {{/isFile}}
   538              {{^isFile}}
   539              $this->formParamsAppend($formParams, '{{baseName}}', ${{paramName}});
   540              {{/isFile}}
   541          }
   542          {{/formParams}}
   543          // body params
   544          $_tempBody = null;
   545          {{#bodyParams}}
   546          if (isset(${{paramName}})) {
   547              $_tempBody = ${{paramName}};
   548          }
   549          {{/bodyParams}}
   550  
   551          if ($multipart) {
   552              $headers = $this->headerSelector->selectHeadersForMultipart(
   553                  [{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]
   554              );
   555          } else {
   556              $headers = $this->headerSelector->selectHeaders(
   557                  [{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}],
   558                  [{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]
   559              );
   560          }
   561  
   562          // for model (json/xml)
   563          if (isset($_tempBody)) {
   564              // $_tempBody is the method argument, if present
   565              if ($headers['Content-Type'] === 'application/json') {
   566                  $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
   567              } else {
   568                  $httpBody = $_tempBody;
   569              }
   570          } elseif (count($formParams) > 0) {
   571              if ($multipart) {
   572                  $multipartContents = [];
   573                  foreach ($formParams as $formParamName => $formParamValue) {
   574                      $multipartContents[] = [
   575                          'name' => $formParamName,
   576                          'contents' => $formParamValue
   577                      ];
   578                  }
   579                  // for HTTP post (form)
   580                  $httpBody = new MultipartStream($multipartContents);
   581  
   582              } elseif ($headers['Content-Type'] === 'application/json') {
   583                  $httpBody = \GuzzleHttp\json_encode($formParams);
   584  
   585              } else {
   586                  // for HTTP post (form)
   587                  $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
   588              }
   589          }
   590  
   591          {{#authMethods}}
   592          {{#isApiKey}}
   593          // this endpoint requires API key authentication
   594          $apiKey = $this->config->getApiKeyWithPrefix('{{keyParamName}}');
   595          if ($apiKey !== null) {
   596              {{#isKeyInHeader}}$headers['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
   597          }
   598          {{/isApiKey}}
   599          {{#isBasic}}
   600          {{#isBasicBasic}}
   601          // this endpoint requires HTTP basic authentication
   602          if (!empty($this->config->getUsername()) || !(empty($this->config->getPassword()))) {
   603              $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword());
   604          }
   605          {{/isBasicBasic}}
   606          {{#isBasicBearer}}
   607          // this endpoint requires Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} authentication (access token)
   608          if ($this->config->getAccessToken() !== null) {
   609              $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
   610          }
   611          {{/isBasicBearer}}
   612          {{/isBasic}}
   613          {{#isOAuth}}
   614          // this endpoint requires OAuth (access token)
   615          if ($this->config->getAccessToken() !== null) {
   616              $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
   617          }
   618          {{/isOAuth}}
   619          {{/authMethods}}
   620  
   621          $defaultHeaders = [];
   622          if ($this->config->getUserAgent()) {
   623              $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
   624          }
   625  
   626          $headers = array_merge(
   627              $defaultHeaders,
   628              $headerParams,
   629              $headers
   630          );
   631  
   632          {{#servers.0}}
   633          $operationHosts = [{{#servers}}"{{{url}}}"{{^-last}}, {{/-last}}{{/servers}}];
   634          if ($this->hostIndex < 0 || $this->hostIndex >= sizeof($operationHosts)) {
   635              throw new \InvalidArgumentException("Invalid index {$this->hostIndex} when selecting the host. Must be less than ".sizeof($operationHosts));
   636          }
   637          $operationHost = $operationHosts[$this->hostIndex];
   638  
   639          {{/servers.0}}
   640          $query = \GuzzleHttp\Psr7\Query::build($queryParams);
   641          return new Request(
   642              '{{httpMethod}}',
   643              {{^servers.0}}$this->config->getHost(){{/servers.0}}{{#servers.0}}$operationHost{{/servers.0}} . $resourcePath . ($query ? "?{$query}" : ''),
   644              $headers,
   645              $httpBody
   646          );
   647      }
   648  
   649      {{/operation}}
   650      /**
   651       * Create http client option
   652       *
   653       * @throws \RuntimeException on file opening failure
   654       * @return array of http client options
   655       */
   656      protected function createHttpClientOption()
   657      {
   658          $options = [];
   659          if ($this->config->getDebug()) {
   660              $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
   661              if (!$options[RequestOptions::DEBUG]) {
   662                  throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
   663              }
   664          }
   665  
   666          return $options;
   667      }
   668      /**
   669       * Append to form params, handle object params
   670       */
   671      protected function formParamsAppend(&$formParams, $name, $value)
   672      {
   673          if (is_object($value)) {
   674              foreach ((array) $value as $k => $v) {
   675                  $formParams[$name.'['.$k.']'] = ObjectSerializer::toFormValue($v);
   676              }
   677  
   678              return;
   679          }
   680  
   681          $formParams[$name] = ObjectSerializer::toFormValue($value);
   682      }
   683  }
   684  {{/operations}}