forked from loafle/openapi-generator-original
[php-symfony] Support for default scalar value of properties in model (#16605)
* Add support for default scalar value of properties in php-symfony models. Default values now returns in getter-functions * Revert nullable type-hinting. Move default values from getter to property initialize. Made changes in __construct: Now value of properties rewrites only if key exist in $data array.
This commit is contained in:
@@ -483,7 +483,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
return dataType;
|
||||
}
|
||||
|
||||
return "\\" + dataType;
|
||||
return "\\" + dataType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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}}
|
||||
|
||||
|
||||
@@ -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}};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user