Skip to content

Commit 6ff3508

Browse files
committed
1 parent 0fab93c commit 6ff3508

File tree

11 files changed

+175
-64
lines changed

11 files changed

+175
-64
lines changed

.openapi-generator/templates/.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'strict_param' => true,
2121
'no_trailing_whitespace' => false,
2222
'no_trailing_whitespace_in_comment' => false,
23-
'braces' => false,
23+
'single_space_around_construct' => true,
2424
'single_blank_line_at_eof' => false,
2525
'blank_line_after_namespace' => false,
2626
'no_leading_import_slash' => false,

.openapi-generator/templates/ApiException.mustache

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
23
/**
34
* ApiException
4-
* PHP version 7.4
5+
* PHP version 7.4+
56
*
67
* @category Class
78
* @package {{invokerPackage}}
@@ -40,7 +41,7 @@ class ApiException extends Exception
4041
/**
4142
* The HTTP header of the server response.
4243
*
43-
* @var string[]|null
44+
* @var string[][]|null
4445
*/
4546
protected $responseHeaders;
4647
@@ -56,7 +57,7 @@ class ApiException extends Exception
5657
*
5758
* @param string $message Error message
5859
* @param int $code HTTP status code
59-
* @param string[]|null $responseHeaders HTTP response header
60+
* @param string[][]|null $responseHeaders HTTP response header
6061
* @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string
6162
*/
6263
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
@@ -69,7 +70,7 @@ class ApiException extends Exception
6970
/**
7071
* Gets the HTTP response header
7172
*
72-
* @return string[]|null HTTP response header
73+
* @return string[][]|null HTTP response header
7374
*/
7475
public function getResponseHeaders()
7576
{

.openapi-generator/templates/Configuration.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
23
/**
34
* Configuration
4-
* PHP version 7.4
5+
* PHP version 7.4+
56
*
67
* @category Class
78
* @package {{invokerPackage}}
@@ -200,7 +201,7 @@ class Configuration
200201
/**
201202
* Sets boolean format for query string.
202203
*
203-
* @param string $booleanFormatForQueryString Boolean format for query string
204+
* @param string $booleanFormat Boolean format for query string
204205
*
205206
* @return $this
206207
*/

.openapi-generator/templates/HeaderSelector.mustache

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
23
/**
34
* HeaderSelector
4-
* PHP version 7.4
5+
* PHP version 7.4+
56
*
67
* @category Class
78
* @package {{invokerPackage}}
@@ -44,7 +45,7 @@ class HeaderSelector
4445
}
4546

4647
if (!$isMultipart) {
47-
if($contentType === '') {
48+
if ($contentType === '') {
4849
$contentType = 'application/json';
4950
}
5051

@@ -76,7 +77,7 @@ class HeaderSelector
7677
}
7778

7879
# If none of the available Accept headers is of type "json", then just use all them
79-
$headersWithJson = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept);
80+
$headersWithJson = $this->selectJsonMimeList($accept);
8081
if (count($headersWithJson) === 0) {
8182
return implode(',', $accept);
8283
}
@@ -86,6 +87,35 @@ class HeaderSelector
8687
return $this->getAcceptHeaderWithAdjustedWeight($accept, $headersWithJson);
8788
}
8889

90+
/**
91+
* Detects whether a string contains a valid JSON mime type
92+
*
93+
* @param string $searchString
94+
* @return bool
95+
*/
96+
public function isJsonMime(string $searchString): bool
97+
{
98+
return preg_match('~^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)~', $searchString) === 1;
99+
}
100+
101+
/**
102+
* Select all items from a list containing a JSON mime type
103+
*
104+
* @param array $mimeList
105+
* @return array
106+
*/
107+
private function selectJsonMimeList(array $mimeList): array
108+
{
109+
$jsonMimeList = [];
110+
foreach ($mimeList as $mime) {
111+
if ($this->isJsonMime($mime)) {
112+
$jsonMimeList[] = $mime;
113+
}
114+
}
115+
return $jsonMimeList;
116+
}
117+
118+
89119
/**
90120
* Create an Accept header string from the given "Accept" headers array, recalculating all weights
91121
*
@@ -120,7 +150,7 @@ class HeaderSelector
120150

121151
$hasMoreThan28Headers = count($accept) > 28;
122152

123-
foreach($processedHeaders as $headers) {
153+
foreach ($processedHeaders as $headers) {
124154
if (count($headers) > 0) {
125155
$acceptHeaders[] = $this->adjustWeight($headers, $currentWeight, $hasMoreThan28Headers);
126156
}
@@ -170,8 +200,7 @@ class HeaderSelector
170200

171201
$acceptHeaders = [];
172202
foreach ($headers as $index => $header) {
173-
if($index > 0 && $headers[$index - 1]['weight'] > $header['weight'])
174-
{
203+
if ($index > 0 && $headers[$index - 1]['weight'] > $header['weight']) {
175204
$currentWeight = $this->getNextWeight($currentWeight, $hasMoreThan28Headers);
176205
}
177206

@@ -192,7 +221,7 @@ class HeaderSelector
192221
*/
193222
private function buildAcceptHeader(string $header, int $weight): string
194223
{
195-
if($weight === 1000) {
224+
if ($weight === 1000) {
196225
return $header;
197226
}
198227

@@ -231,6 +260,6 @@ class HeaderSelector
231260
return $currentWeight - 1;
232261
}
233262

234-
return $currentWeight - 10 ** floor( log10($currentWeight - 1) );
263+
return $currentWeight - 10 ** floor(log10($currentWeight - 1));
235264
}
236265
}

.openapi-generator/templates/ModelInterface.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2+
23
/**
34
* ModelInterface
45
*
5-
* PHP version 7.4
6+
* PHP version 7.4+
67
*
78
* @category Class
89
* @package {{modelPackage}}

.openapi-generator/templates/ObjectSerializer.mustache

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2+
23
/**
34
* ObjectSerializer
45
*
5-
* PHP version 7.4
6+
* PHP version 7.4+
67
*
78
* @category Class
89
* @package {{invokerPackage}}
@@ -182,12 +183,16 @@ class ObjectSerializer
182183
case 'float':
183184
return $value !== 0 && $value !== 0.0;
184185
185-
# For boolean values, '' is considered empty
186+
# For boolean values, '' is considered empty
186187
case 'bool':
187188
case 'boolean':
188189
return !in_array($value, [false, 0], true);
189190
190-
# For all the other types, any value at this point can be considered empty.
191+
# For string values, '' is considered empty.
192+
case 'string':
193+
return $value === '';
194+
195+
# For all the other types, any value at this point can be considered empty.
191196
default:
192197
return true;
193198
}
@@ -242,6 +247,7 @@ class ObjectSerializer
242247
return $arr;
243248
}
244249
250+
245251
foreach ($arr as $k => $v) {
246252
$prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k;
247253
@@ -260,6 +266,11 @@ class ObjectSerializer
260266
261267
$value = $flattenArray($value, $paramName);
262268
269+
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
270+
if ($openApiType === 'array' && $style === 'deepObject' && $explode) {
271+
return $value;
272+
}
273+
263274
if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) {
264275
return $value;
265276
}
@@ -283,7 +294,7 @@ class ObjectSerializer
283294
*/
284295
public static function convertBoolToQueryStringFormat(bool $value)
285296
{
286-
if (Configuration::BOOLEAN_FORMAT_STRING == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) {
297+
if (Configuration::BOOLEAN_FORMAT_STRING === Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) {
287298
return $value ? 'true' : 'false';
288299
}
289300
@@ -333,7 +344,7 @@ class ObjectSerializer
333344
* If it's a datetime object, format it in ISO8601
334345
* If it's a boolean, convert it to "true" or "false".
335346
*
336-
* @param string|bool|\DateTime $value the value of the parameter
347+
* @param float|int|bool|\DateTime $value the value of the parameter
337348
*
338349
* @return string the header string
339350
*/
@@ -391,7 +402,6 @@ class ObjectSerializer
391402
* @param mixed $data object or primitive to be deserialized
392403
* @param string $class class name is passed as a string
393404
* @param string[] $httpHeaders HTTP headers
394-
* @param string $discriminator discriminator if polymorphism is used
395405
*
396406
* @return object|array|null a single or an array of $class instances
397407
*/
@@ -541,22 +551,64 @@ class ObjectSerializer
541551
}
542552

543553
/**
544-
* Native `http_build_query` wrapper.
545-
* @see https://www.php.net/manual/en/function.http-build-query
546-
*
547-
* @param array|object $data May be an array or object containing properties.
548-
* @param string $numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only.
549-
* @param string|null $arg_separator arg_separator.output is used to separate arguments but may be overridden by specifying this parameter.
550-
* @param int $encoding_type Encoding type. By default, PHP_QUERY_RFC1738.
551-
*
552-
* @return string
553-
*/
554-
public static function buildQuery(
555-
$data,
556-
string $numeric_prefix = '',
557-
?string $arg_separator = null,
558-
int $encoding_type = \PHP_QUERY_RFC3986
559-
): string {
560-
return \GuzzleHttp\Psr7\Query::build($data, $encoding_type);
554+
* Build a query string from an array of key value pairs.
555+
*
556+
* This function can use the return value of `parse()` to build a query
557+
* string. This function does not modify the provided keys when an array is
558+
* encountered (like `http_build_query()` would).
559+
*
560+
* The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112
561+
* with a modification which is described in https://github.com/guzzle/psr7/pull/603
562+
*
563+
* @param array $params Query string parameters.
564+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
565+
* to encode using RFC3986, or PHP_QUERY_RFC1738
566+
* to encode using RFC1738.
567+
*/
568+
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
569+
{
570+
if (!$params) {
571+
return '';
572+
}
573+
574+
if ($encoding === false) {
575+
$encoder = function (string $str): string {
576+
return $str;
577+
};
578+
} elseif ($encoding === PHP_QUERY_RFC3986) {
579+
$encoder = 'rawurlencode';
580+
} elseif ($encoding === PHP_QUERY_RFC1738) {
581+
$encoder = 'urlencode';
582+
} else {
583+
throw new \InvalidArgumentException('Invalid type');
584+
}
585+
586+
$castBool = Configuration::BOOLEAN_FORMAT_INT === Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()
587+
? function ($v) { return (int) $v; }
588+
: function ($v) { return $v ? 'true' : 'false'; };
589+
590+
$qs = '';
591+
foreach ($params as $k => $v) {
592+
$k = $encoder((string) $k);
593+
if (!is_array($v)) {
594+
$qs .= $k;
595+
$v = is_bool($v) ? $castBool($v) : $v;
596+
if ($v !== null) {
597+
$qs .= '='.$encoder((string) $v);
598+
}
599+
$qs .= '&';
600+
} else {
601+
foreach ($v as $vv) {
602+
$qs .= $k;
603+
$vv = is_bool($vv) ? $castBool($vv) : $vv;
604+
if ($vv !== null) {
605+
$qs .= '='.$encoder((string) $vv);
606+
}
607+
$qs .= '&';
608+
}
609+
}
610+
}
611+
612+
return $qs ? (string) substr($qs, 0, -1) : '';
561613
}
562614
}

0 commit comments

Comments
 (0)