Skip to content

Commit 7a98580

Browse files
committed
2 parents b72d5ca + ec815ca commit 7a98580

68 files changed

Lines changed: 868 additions & 593 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/apex/OAS.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public class OAS {
183183

184184
@TestVisible
185185
protected virtual Object toReturnValue(String body, Type returnType, String contentType) {
186-
if (contentType == 'application/json') {
186+
if (contentType.contains('application/json')) {
187187
Object o = returnType.newInstance();
188188
if (o instanceof MappedProperties) {
189189
Map<String, String> propertyMappings = ((MappedProperties) o).getPropertyMappings();

modules/openapi-generator/src/main/resources/php/ApiException.mustache

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ApiException extends Exception
3434
/**
3535
* The HTTP body of the server response either as Json or string.
3636
*
37-
* @var mixed
37+
* @var \stdClass|string|null
3838
*/
3939
protected $responseBody;
4040
@@ -48,17 +48,17 @@ class ApiException extends Exception
4848
/**
4949
* The deserialized response object
5050
*
51-
* @var $responseObject;
51+
* @var \stdClass|string|null
5252
*/
5353
protected $responseObject;
5454
5555
/**
5656
* Constructor
5757
*
58-
* @param string $message Error message
59-
* @param int $code HTTP status code
60-
* @param string[]|null $responseHeaders HTTP response header
61-
* @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string
58+
* @param string $message Error message
59+
* @param int $code HTTP status code
60+
* @param string[]|null $responseHeaders HTTP response header
61+
* @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string
6262
*/
6363
public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null)
6464
{
@@ -80,7 +80,7 @@ class ApiException extends Exception
8080
/**
8181
* Gets the HTTP body of the server response either as Json or string
8282
*
83-
* @return mixed HTTP body of the server response either as \stdClass or string
83+
* @return \stdClass|string|null HTTP body of the server response either as \stdClass or string
8484
*/
8585
public function getResponseBody()
8686
{

modules/openapi-generator/src/main/resources/php/Configuration.mustache

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace {{invokerPackage}};
2929
*/
3030
class Configuration
3131
{
32+
/**
33+
* @var Configuration
34+
*/
3235
private static $defaultConfiguration;
3336
3437
/**
@@ -128,7 +131,7 @@ class Configuration
128131
*
129132
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
130133
*
131-
* @return string API key or token
134+
* @return null|string API key or token
132135
*/
133136
public function getApiKey($apiKeyIdentifier)
134137
{
@@ -154,7 +157,7 @@ class Configuration
154157
*
155158
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
156159
*
157-
* @return string
160+
* @return null|string
158161
*/
159162
public function getApiKeyPrefix($apiKeyIdentifier)
160163
{
@@ -400,7 +403,7 @@ class Configuration
400403
*
401404
* @param string $apiKeyIdentifier name of apikey
402405
*
403-
* @return string API key with the prefix
406+
* @return null|string API key with the prefix
404407
*/
405408
public function getApiKeyWithPrefix($apiKeyIdentifier)
406409
{
@@ -423,7 +426,7 @@ class Configuration
423426
/**
424427
* Returns an array of host settings
425428
*
426-
* @return an array of host settings
429+
* @return array an array of host settings
427430
*/
428431
public function getHostSettings()
429432
{
@@ -461,9 +464,9 @@ class Configuration
461464
/**
462465
* Returns URL based on the index and variables
463466
*
464-
* @param index array index of the host settings
465-
* @param variables hash of variable and the corresponding value (optional)
466-
* @return URL based on host settings
467+
* @param int $index index of the host settings
468+
* @param array|null $variables hash of variable and the corresponding value (optional)
469+
* @return string URL based on host settings
467470
*/
468471
public function getHostFromSettings($index, $variables = null)
469472
{

modules/openapi-generator/src/main/resources/php/HeaderSelector.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class HeaderSelector
6666
*
6767
* @param string[] $accept Array of header
6868
*
69-
* @return string Accept (e.g. application/json)
69+
* @return null|string Accept (e.g. application/json)
7070
*/
7171
private function selectAcceptHeader($accept)
7272
{

modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,26 @@ class ObjectSerializer
5151
* @param string $type the OpenAPIToolsType of the data
5252
* @param string $format the format of the OpenAPITools type of the data
5353
*
54-
* @return string|object serialized form of $data
54+
* @return scalar|object|array|null serialized form of $data
5555
*/
5656
public static function sanitizeForSerialization($data, $type = null, $format = null)
5757
{
5858
if (is_scalar($data) || null === $data) {
5959
return $data;
60-
} elseif ($data instanceof \DateTime) {
60+
}
61+
62+
if ($data instanceof \DateTime) {
6163
return ($format === 'date') ? $data->format('Y-m-d') : $data->format(self::$dateTimeFormat);
62-
} elseif (is_array($data)) {
64+
}
65+
66+
if (is_array($data)) {
6367
foreach ($data as $property => $value) {
6468
$data[$property] = self::sanitizeForSerialization($value);
6569
}
6670
return $data;
67-
} elseif (is_object($data)) {
71+
}
72+
73+
if (is_object($data)) {
6874
$values = [];
6975
if ($data instanceof ModelInterface) {
7076
$formats = $data::openAPIFormats();
@@ -250,7 +256,9 @@ class ObjectSerializer
250256
{
251257
if (null === $data) {
252258
return null;
253-
} elseif (strcasecmp(substr($class, -2), '[]') === 0) {
259+
}
260+
261+
if (strcasecmp(substr($class, -2), '[]') === 0) {
254262
$data = is_string($data) ? json_decode($data) : $data;
255263
256264
if (!is_array($data)) {
@@ -263,7 +271,9 @@ class ObjectSerializer
263271
$values[] = self::deserialize($value, $subClass, null);
264272
}
265273
return $values;
266-
} elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
274+
}
275+
276+
if (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
267277
$data = is_string($data) ? json_decode($data) : $data;
268278
settype($data, 'array');
269279
$inner = substr($class, 4, -1);
@@ -276,10 +286,14 @@ class ObjectSerializer
276286
}
277287
}
278288
return $deserialized;
279-
} elseif ($class === 'object') {
289+
}
290+
291+
if ($class === 'object') {
280292
settype($data, 'array');
281293
return $data;
282-
} elseif ($class === '\DateTime') {
294+
}
295+
296+
if ($class === '\DateTime') {
283297
// Some API's return an invalid, empty string as a
284298
// date-time property. DateTime::__construct() will return
285299
// the current time for empty input which is probably not
@@ -291,10 +305,14 @@ class ObjectSerializer
291305
} else {
292306
return null;
293307
}
294-
} elseif (in_array($class, [{{&primitives}}], true)) {
308+
}
309+
310+
if (in_array($class, [{{&primitives}}], true)) {
295311
settype($data, $class);
296312
return $data;
297-
} elseif ($class === '\SplFileObject') {
313+
}
314+
315+
if ($class === '\SplFileObject') {
298316
/** @var \Psr\Http\Message\StreamInterface $data */
299317
300318
// determine file name

modules/openapi-generator/src/main/resources/php/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ use {{invokerPackage}}\ObjectSerializer;
8080
/**
8181
* Set the host index
8282
*
83-
* @param int Host index (required)
83+
* @param int $hostIndex Host index (required)
8484
*/
85-
public function setHostIndex($host_index)
85+
public function setHostIndex($hostIndex)
8686
{
87-
$this->hostIndex = $host_index;
87+
$this->hostIndex = $hostIndex;
8888
}
8989

9090
/**
9191
* Get the host index
9292
*
93-
* @return Host index
93+
* @return int Host index
9494
*/
9595
public function getHostIndex()
9696
{

modules/openapi-generator/src/main/resources/php/api_test.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Please update the test case below to test the endpoint.
1717
*/
1818

19-
namespace {{invokerPackage}};
19+
namespace {{invokerPackage}}\Test\Api;
2020

2121
use \{{invokerPackage}}\Configuration;
2222
use \{{invokerPackage}}\ApiException;
@@ -71,6 +71,8 @@ use PHPUnit\Framework\TestCase;
7171
*/
7272
public function test{{vendorExtensions.x-test-operation-id}}()
7373
{
74+
// TODO: implement
75+
$this->markTestIncomplete('Not implemented');
7476
}
7577
{{/operation}}
7678
}

modules/openapi-generator/src/main/resources/php/composer.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
3737
},
3838
"autoload-dev": {
39-
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{testBasePath}}/" }
39+
"psr-4": { "{{escapedInvokerPackage}}\\Test\\" : "{{testBasePath}}/" }
4040
}
4141
}

modules/openapi-generator/src/main/resources/php/model.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ use \{{invokerPackage}}\ObjectSerializer;
3838
* @package {{invokerPackage}}
3939
* @author OpenAPI Generator team
4040
* @link https://openapi-generator.tech
41+
{{^isEnum}}
42+
* @implements \ArrayAccess<TKey, TValue>
43+
* @template TKey int|null
44+
* @template TValue mixed|null
45+
{{/isEnum}}
4146
*/
4247
{{#isEnum}}{{>model_enum}}{{/isEnum}}{{^isEnum}}{{>model_generic}}{{/isEnum}}
4348
{{/model}}{{/models}}

modules/openapi-generator/src/main/resources/php/model_generic.mustache

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^parentSchema}}implements ModelInterface, ArrayAccess{{/parentSchema}}
22
{
3-
const DISCRIMINATOR = {{#discriminator}}'{{discriminatorName}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};
3+
public const DISCRIMINATOR = {{#discriminator}}'{{discriminatorName}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};
44

55
/**
66
* The original name of the model.
@@ -23,6 +23,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
2323
* Array of property to format mappings. Used for (de)serialization
2424
*
2525
* @var string[]
26+
* @phpstan-var array<string, string|null>
27+
* @psalm-var array<string, string|null>
2628
*/
2729
protected static $openAPIFormats = [
2830
{{#vars}}'{{name}}' => {{#dataFormat}}'{{{dataFormat}}}'{{/dataFormat}}{{^dataFormat}}null{{/dataFormat}}{{#hasMore}},
@@ -161,7 +163,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
161163

162164
{{/parentSchema}}
163165
{{#vars}}
164-
$this->container['{{name}}'] = isset($data['{{name}}']) ? $data['{{name}}'] : {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}};
166+
$this->container['{{name}}'] = $data['{{name}}'] ?? {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}};
165167
{{/vars}}
166168
{{#discriminator}}
167169

@@ -278,7 +280,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
278280
*
279281
* @param {{dataType}}{{^required}}|null{{/required}} ${{name}}{{#description}} {{{description}}}{{/description}}{{^description}} {{{name}}}{{/description}}
280282
*
281-
* @return $this
283+
* @return self
282284
*/
283285
public function {{setter}}(${{name}})
284286
{
@@ -362,18 +364,18 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
362364
*
363365
* @param integer $offset Offset
364366
*
365-
* @return mixed
367+
* @return mixed|null
366368
*/
367369
public function offsetGet($offset)
368370
{
369-
return isset($this->container[$offset]) ? $this->container[$offset] : null;
371+
return isset($this->container[$offset]) ?? null;
370372
}
371373

372374
/**
373375
* Sets value based on offset.
374376
*
375-
* @param integer $offset Offset
376-
* @param mixed $value Value to be set
377+
* @param int|null $offset Offset
378+
* @param mixed $value Value to be set
377379
*
378380
* @return void
379381
*/

0 commit comments

Comments
 (0)