diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index a5b5f227269d..177f8600e55d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -483,7 +483,7 @@ public String prependSlashToDataTypeOnlyIfNecessary(String dataType) { return dataType; } - return "\\" + dataType; + return "\\" + dataType; } /** diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache index 5b093b479d46..2c3636040279 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_generic.mustache @@ -12,9 +12,11 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} parent::__construct($data); {{/parentSchema}} - {{#vars}} - $this->{{name}} = $data['{{name}}'] ?? null; - {{/vars}} + if (is_array($data)) { + {{#vars}} + $this->{{name}} = array_key_exists('{{name}}', $data) ? $data['{{name}}'] : $this->{{name}}; + {{/vars}} + } } {{#vars}} diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache index 4a77c9a46385..7855e1e1c457 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache @@ -98,4 +98,4 @@ {{/minItems}} {{/hasValidation}} */ - protected {{{vendorExtensions.x-parameter-type}}} ${{name}} = null; + protected {{{vendorExtensions.x-parameter-type}}} ${{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}; diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php index 21b86eeae337..218d4f85afb4 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -74,9 +74,11 @@ class ApiResponse */ public function __construct(array $data = null) { - $this->code = $data['code'] ?? null; - $this->type = $data['type'] ?? null; - $this->message = $data['message'] ?? null; + if (is_array($data)) { + $this->code = array_key_exists('code', $data) ? $data['code'] : $this->code; + $this->type = array_key_exists('type', $data) ? $data['type'] : $this->type; + $this->message = array_key_exists('message', $data) ? $data['message'] : $this->message; + } } /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php index fac8878d4644..2ea80a897b63 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -67,8 +67,10 @@ class Category */ public function __construct(array $data = null) { - $this->id = $data['id'] ?? null; - $this->name = $data['name'] ?? null; + if (is_array($data)) { + $this->id = array_key_exists('id', $data) ? $data['id'] : $this->id; + $this->name = array_key_exists('name', $data) ? $data['name'] : $this->name; + } } /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php index 72c6a15db0dc..d902d49a2ab3 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -93,7 +93,7 @@ class Order * @Assert\Type("bool") * @Type("bool") */ - protected ?bool $complete = null; + protected ?bool $complete = false; /** * Constructor @@ -101,12 +101,14 @@ class Order */ public function __construct(array $data = null) { - $this->id = $data['id'] ?? null; - $this->petId = $data['petId'] ?? null; - $this->quantity = $data['quantity'] ?? null; - $this->shipDate = $data['shipDate'] ?? null; - $this->status = $data['status'] ?? null; - $this->complete = $data['complete'] ?? null; + if (is_array($data)) { + $this->id = array_key_exists('id', $data) ? $data['id'] : $this->id; + $this->petId = array_key_exists('petId', $data) ? $data['petId'] : $this->petId; + $this->quantity = array_key_exists('quantity', $data) ? $data['quantity'] : $this->quantity; + $this->shipDate = array_key_exists('shipDate', $data) ? $data['shipDate'] : $this->shipDate; + $this->status = array_key_exists('status', $data) ? $data['status'] : $this->status; + $this->complete = array_key_exists('complete', $data) ? $data['complete'] : $this->complete; + } } /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php index 6a400e7c2486..0ba0114642f6 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -107,12 +107,14 @@ class Pet */ public function __construct(array $data = null) { - $this->id = $data['id'] ?? null; - $this->category = $data['category'] ?? null; - $this->name = $data['name'] ?? null; - $this->photoUrls = $data['photoUrls'] ?? null; - $this->tags = $data['tags'] ?? null; - $this->status = $data['status'] ?? null; + if (is_array($data)) { + $this->id = array_key_exists('id', $data) ? $data['id'] : $this->id; + $this->category = array_key_exists('category', $data) ? $data['category'] : $this->category; + $this->name = array_key_exists('name', $data) ? $data['name'] : $this->name; + $this->photoUrls = array_key_exists('photoUrls', $data) ? $data['photoUrls'] : $this->photoUrls; + $this->tags = array_key_exists('tags', $data) ? $data['tags'] : $this->tags; + $this->status = array_key_exists('status', $data) ? $data['status'] : $this->status; + } } /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php index 3ee1398a4840..08f6550d182a 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -66,8 +66,10 @@ class Tag */ public function __construct(array $data = null) { - $this->id = $data['id'] ?? null; - $this->name = $data['name'] ?? null; + if (is_array($data)) { + $this->id = array_key_exists('id', $data) ? $data['id'] : $this->id; + $this->name = array_key_exists('name', $data) ? $data['name'] : $this->name; + } } /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php index 179ec3f173b6..129657df957c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -116,14 +116,16 @@ class User */ public function __construct(array $data = null) { - $this->id = $data['id'] ?? null; - $this->username = $data['username'] ?? null; - $this->firstName = $data['firstName'] ?? null; - $this->lastName = $data['lastName'] ?? null; - $this->email = $data['email'] ?? null; - $this->password = $data['password'] ?? null; - $this->phone = $data['phone'] ?? null; - $this->userStatus = $data['userStatus'] ?? null; + if (is_array($data)) { + $this->id = array_key_exists('id', $data) ? $data['id'] : $this->id; + $this->username = array_key_exists('username', $data) ? $data['username'] : $this->username; + $this->firstName = array_key_exists('firstName', $data) ? $data['firstName'] : $this->firstName; + $this->lastName = array_key_exists('lastName', $data) ? $data['lastName'] : $this->lastName; + $this->email = array_key_exists('email', $data) ? $data['email'] : $this->email; + $this->password = array_key_exists('password', $data) ? $data['password'] : $this->password; + $this->phone = array_key_exists('phone', $data) ? $data['phone'] : $this->phone; + $this->userStatus = array_key_exists('userStatus', $data) ? $data['userStatus'] : $this->userStatus; + } } /**