diff --git a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache index 026bd4fb3acb..3a061043642a 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/composer.mustache @@ -28,6 +28,7 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", + "doctrine/annotations": "^2.0", "symfony/validator": "^6.4|^7.0", "jms/serializer-bundle": "^5.4", "symfony/framework-bundle": "^6.4|^7.0" 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 620051725deb..9dba64f5345c 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 @@ -30,6 +30,20 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} return $this->{{name}}; } + /** + * Sets {{name}}. + * + * @param {{{vendorExtensions.x-comment-type}}} ${{name}}{{#description}} {{{.}}}{{/description}} + * + * @return $this + */ + public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}): self + { + $this->{{name}} = ${{name}}; + + return $this; + } + {{#isEnumRef}} /** * Gets {{name}} for serialization. @@ -40,6 +54,24 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} { return $this->{{name}}?->value ? (string) $this->{{name}}->value : null; } + + /** + * Sets {{name}}. + * + * @param string|{{{vendorExtensions.x-comment-type}}} ${{name}}{{#description}} {{{.}}}{{/description}} + * + * @return $this + */ + public function setDeserialized{{nameInPascalCase}}(string|{{#vendorExtensions.x-comment-type}}{{vendorExtensions.x-comment-type}} {{/vendorExtensions.x-comment-type}}${{name}}{{^required}} = null{{/required}}): self + { + if (is_string(${{name}})) { + ${{name}} = {{baseType}}::tryFrom(${{name}}); + } + + $this->{{name}} = ${{name}}; + + return $this; + } {{/isEnumRef}} {{#isContainer}} @@ -53,26 +85,36 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}} public function getSerialized{{nameInPascalCase}}(): array { return array_map( - static fn ($value) => (string) $value->value, - $this->test ?? [] + static fn ($value) => $value?->value ? (string) $value->value : null, + $this->{{name}} ?? [] ); } - {{/isEnumRef}} - {{/items}} - {{/isContainer}} /** - * Sets {{name}}. - * - * @param {{{vendorExtensions.x-comment-type}}} ${{name}}{{#description}} {{{.}}}{{/description}} - * - * @return $this - */ - public function {{setter}}({{#vendorExtensions.x-parameter-type}}{{vendorExtensions.x-parameter-type}} {{/vendorExtensions.x-parameter-type}}${{name}}{{^required}} = null{{/required}}): self + * Sets {{name}}. + * + * @param {{^required}}?{{/required}}array ${{name}}{{#description}} {{{.}}}{{/description}} + * + * @return $this + */ + public function setDeserialized{{nameInPascalCase}}({{^required}}?{{/required}}array ${{name}}{{^required}} = []{{/required}}): self { - $this->{{name}} = ${{name}}; + $this->{{name}} = array_map( + static function ($value) { + if (is_string($value)) { + $value = {{baseType}}::tryFrom($value); + } + + return $value; + }, + ${{name}} ?? [] + ); return $this; } + {{/isEnumRef}} + {{/items}} + {{/isContainer}} + {{/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 8e403f458914..f52d6b065af2 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 @@ -5,30 +5,7 @@ {{/description}} * @var {{{vendorExtensions.x-comment-type}}} * @SerializedName("{{baseName}}") -{{#required}} - * @Assert\NotNull() - {{^isPrimitiveType}} - * @Assert\Valid() - {{/isPrimitiveType}} -{{/required}} -{{#isEnum}} - {{#isContainer}} - * @Assert\All({ - {{#items}} - * @Assert\Choice({ {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} }) - {{/items}} - * }) - {{/isContainer}} - {{^isContainer}} - * @Assert\Choice({ {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} }) - {{/isContainer}} -{{/isEnum}} {{#isContainer}} - * @Assert\All({ - {{#items}} - * @Assert\Type("{{dataType}}") - {{/items}} - * }) {{#isMap}} {{#items}} * @Type("array") @@ -37,7 +14,7 @@ {{^isMap}} {{#items}} {{#isEnumRef}} - * @Accessor(getter="getSerialized{{nameInPascalCase}}") + * @Accessor(getter="getSerialized{{nameInPascalCase}}", setter="setDeserialized{{nameInPascalCase}}") * @Type("array") {{/isEnumRef}} {{^isEnumRef}} @@ -48,66 +25,95 @@ {{/isContainer}} {{^isContainer}} {{#isDate}} - * @Assert\Type("\Date") * @Type("DateTime<'Y-m-d'>") {{/isDate}} {{#isDateTime}} - * @Assert\Type("\DateTime")) * @Type("DateTime") {{/isDateTime}} {{#isEnumRef}} - * @Accessor(getter="getSerialized{{nameInPascalCase}}") - * @Type("string") + * @Accessor(getter="getSerialized{{nameInPascalCase}}", setter="setDeserialized{{nameInPascalCase}}") + * @Type("string") {{/isEnumRef}} {{^isDate}} {{^isDateTime}} {{^isEnumRef}} - * @Assert\Type("{{dataType}}") * @Type("{{dataType}}") {{/isEnumRef}} {{/isDateTime}} {{/isDate}} +{{/isContainer}} + */ +{{#required}} + #[Assert\NotNull] + {{^isPrimitiveType}} + #[Assert\Valid] + {{/isPrimitiveType}} +{{/required}} +{{#isEnum}} + {{#isContainer}} + #[Assert\All([ + {{#items}} + new Assert\Choice([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]), + {{/items}} + ])] + {{/isContainer}} + {{^isContainer}} + #[Assert\Choice([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}])] + {{/isContainer}} +{{/isEnum}} +{{#isContainer}} + #[Assert\All([ + {{#items}} + new Assert\Type("{{dataType}}"), + {{/items}} + ])] +{{/isContainer}} +{{^isContainer}} + {{#isDate}} + #[Assert\Type("\DateTime")] + {{/isDate}} + {{#isDateTime}} + #[Assert\Type("\DateTime")] + {{/isDateTime}} + {{^isDate}} + {{^isDateTime}} + {{^isEnumRef}} + #[Assert\Type("{{dataType}}")] + {{/isEnumRef}} + {{/isDateTime}} + {{/isDate}} {{/isContainer}} {{#hasValidation}} {{#maxLength}} - * @Assert\Length( - * max = {{.}} - * ) + #[Assert\Length(max: {{.}})] {{/maxLength}} {{#minLength}} - * @Assert\Length( - * min = {{.}} - * ) + #[Assert\Length(min: {{.}})] {{/minLength}} {{#minimum}} {{#exclusiveMinimum}} - * @Assert\GreaterThan({{minimum}}) + #[Assert\GreaterThan({{minimum}})] {{/exclusiveMinimum}} {{^exclusiveMinimum}} - * @Assert\GreaterThanOrEqual({{minimum}}) + #[Assert\GreaterThanOrEqual({{minimum}})] {{/exclusiveMinimum}} {{/minimum}} {{#maximum}} {{#exclusiveMaximum}} - * @Assert\LessThan({{maximum}}) + #[Assert\LessThan({{maximum}})] {{/exclusiveMaximum}} {{^exclusiveMaximum}} - * @Assert\LessThanOrEqual({{maximum}}) + #[Assert\LessThanOrEqual({{maximum}})] {{/exclusiveMaximum}} {{/maximum}} {{#pattern}} - * @Assert\Regex("/{{.}}/") + #[Assert\Regex("/{{.}}/")] {{/pattern}} {{#maxItems}} - * @Assert\Count( - * max = {{.}} - * ) + #[Assert\Count(max: {{.}})] {{/maxItems}} {{#minItems}} - * @Assert\Count( - * min = {{.}} - * ) + #[Assert\Count(min: {{.}})] {{/minItems}} {{/hasValidation}} - */ protected {{{vendorExtensions.x-parameter-type}}} ${{name}} = {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}; diff --git a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache index e5ff50c3f7fe..9dfabc9733a3 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/serialization/JmsSerializer.mustache @@ -101,12 +101,16 @@ class JmsSerializer implements SerializerInterface case '\DateTime': return is_null($data) ? null :new DateTime($data); default: + if (is_null($data)) { + return null; + } + if (!class_exists($type)) { throw new RuntimeException(sprintf("Type %s is unsupported", $type)); } $reflectionClass = new \ReflectionClass($type); - if (!$reflectionClass->implementsInterface('\BackedENum')) { + if (!$reflectionClass->implementsInterface('\BackedEnum')) { throw new RuntimeException(sprintf("Type %s is unsupported", $type)); } 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 69f4ccd2777a..e7c2de6ce033 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -48,25 +48,25 @@ class ApiResponse /** * @var int|null * @SerializedName("code") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $code = null; /** * @var string|null * @SerializedName("type") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $type = null; /** * @var string|null * @SerializedName("message") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $message = null; /** @@ -92,15 +92,13 @@ public function getCode(): ?int return $this->code; } - - /** - * Sets code. - * - * @param int|null $code - * - * @return $this - */ + * Sets code. + * + * @param int|null $code + * + * @return $this + */ public function setCode(?int $code = null): self { $this->code = $code; @@ -108,6 +106,9 @@ public function setCode(?int $code = null): self return $this; } + + + /** * Gets type. * @@ -118,15 +119,13 @@ public function getType(): ?string return $this->type; } - - /** - * Sets type. - * - * @param string|null $type - * - * @return $this - */ + * Sets type. + * + * @param string|null $type + * + * @return $this + */ public function setType(?string $type = null): self { $this->type = $type; @@ -134,6 +133,9 @@ public function setType(?string $type = null): self return $this; } + + + /** * Gets message. * @@ -144,21 +146,22 @@ public function getMessage(): ?string return $this->message; } - - /** - * Sets message. - * - * @param string|null $message - * - * @return $this - */ + * Sets message. + * + * @param string|null $message + * + * @return $this + */ public function setMessage(?string $message = null): self { $this->message = $message; return $this; } + + + } 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 8cecd5ca1a65..fc827e4ae735 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -48,18 +48,18 @@ class Category /** * @var int|null * @SerializedName("id") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $id = null; /** * @var string|null * @SerializedName("name") - * @Assert\Type("string") * @Type("string") - * @Assert\Regex("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/") - */ + */ + #[Assert\Type("string")] + #[Assert\Regex("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/")] protected ?string $name = null; /** @@ -84,15 +84,13 @@ public function getId(): ?int return $this->id; } - - /** - * Sets id. - * - * @param int|null $id - * - * @return $this - */ + * Sets id. + * + * @param int|null $id + * + * @return $this + */ public function setId(?int $id = null): self { $this->id = $id; @@ -100,6 +98,9 @@ public function setId(?int $id = null): self return $this; } + + + /** * Gets name. * @@ -110,21 +111,22 @@ public function getName(): ?string return $this->name; } - - /** - * Sets name. - * - * @param string|null $name - * - * @return $this - */ + * Sets name. + * + * @param string|null $name + * + * @return $this + */ public function setName(?string $name = null): self { $this->name = $name; return $this; } + + + } 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 ae3f8fb0c5d5..6434aa9121f8 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -48,33 +48,33 @@ class Order /** * @var int|null * @SerializedName("id") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $id = null; /** * @var int|null * @SerializedName("petId") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $petId = null; /** * @var int|null * @SerializedName("quantity") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $quantity = null; /** * @var \DateTime|null * @SerializedName("shipDate") - * @Assert\Type("\DateTime")) * @Type("DateTime") - */ + */ + #[Assert\Type("\DateTime")] protected ?\DateTime $shipDate = null; /** @@ -82,18 +82,18 @@ class Order * * @var string|null * @SerializedName("status") - * @Assert\Choice({ "placed", "approved", "delivered" }) - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Choice(["placed", "approved", "delivered"])] + #[Assert\Type("string")] protected ?string $status = null; /** * @var bool|null * @SerializedName("complete") - * @Assert\Type("bool") * @Type("bool") - */ + */ + #[Assert\Type("bool")] protected ?bool $complete = false; /** @@ -122,15 +122,13 @@ public function getId(): ?int return $this->id; } - - /** - * Sets id. - * - * @param int|null $id - * - * @return $this - */ + * Sets id. + * + * @param int|null $id + * + * @return $this + */ public function setId(?int $id = null): self { $this->id = $id; @@ -138,6 +136,9 @@ public function setId(?int $id = null): self return $this; } + + + /** * Gets petId. * @@ -148,15 +149,13 @@ public function getPetId(): ?int return $this->petId; } - - /** - * Sets petId. - * - * @param int|null $petId - * - * @return $this - */ + * Sets petId. + * + * @param int|null $petId + * + * @return $this + */ public function setPetId(?int $petId = null): self { $this->petId = $petId; @@ -164,6 +163,9 @@ public function setPetId(?int $petId = null): self return $this; } + + + /** * Gets quantity. * @@ -174,15 +176,13 @@ public function getQuantity(): ?int return $this->quantity; } - - /** - * Sets quantity. - * - * @param int|null $quantity - * - * @return $this - */ + * Sets quantity. + * + * @param int|null $quantity + * + * @return $this + */ public function setQuantity(?int $quantity = null): self { $this->quantity = $quantity; @@ -190,6 +190,9 @@ public function setQuantity(?int $quantity = null): self return $this; } + + + /** * Gets shipDate. * @@ -200,15 +203,13 @@ public function getShipDate(): ?\DateTime return $this->shipDate; } - - /** - * Sets shipDate. - * - * @param \DateTime|null $shipDate - * - * @return $this - */ + * Sets shipDate. + * + * @param \DateTime|null $shipDate + * + * @return $this + */ public function setShipDate(?\DateTime $shipDate = null): self { $this->shipDate = $shipDate; @@ -216,6 +217,9 @@ public function setShipDate(?\DateTime $shipDate = null): self return $this; } + + + /** * Gets status. * @@ -226,15 +230,13 @@ public function getStatus(): ?string return $this->status; } - - /** - * Sets status. - * - * @param string|null $status Order Status - * - * @return $this - */ + * Sets status. + * + * @param string|null $status Order Status + * + * @return $this + */ public function setStatus(?string $status = null): self { $this->status = $status; @@ -242,6 +244,9 @@ public function setStatus(?string $status = null): self return $this; } + + + /** * Gets complete. * @@ -252,21 +257,22 @@ public function isComplete(): ?bool return $this->complete; } - - /** - * Sets complete. - * - * @param bool|null $complete - * - * @return $this - */ + * Sets complete. + * + * @param bool|null $complete + * + * @return $this + */ public function setComplete(?bool $complete = null): self { $this->complete = $complete; return $this; } + + + } 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 2225627acf2c..deda58c617ee 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -48,47 +48,47 @@ class Pet /** * @var int|null * @SerializedName("id") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $id = null; /** * @var Category|null * @SerializedName("category") - * @Assert\Type("OpenAPI\Server\Model\Category") * @Type("OpenAPI\Server\Model\Category") - */ + */ + #[Assert\Type("OpenAPI\Server\Model\Category")] protected ?Category $category = null; /** * @var string|null * @SerializedName("name") - * @Assert\NotNull() - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\NotNull] + #[Assert\Type("string")] protected ?string $name = null; /** * @var string[]|null * @SerializedName("photoUrls") - * @Assert\NotNull() - * @Assert\All({ - * @Assert\Type("string") - * }) * @Type("array") - */ + */ + #[Assert\NotNull] + #[Assert\All([ + new Assert\Type("string"), + ])] protected ?array $photoUrls = null; /** * @var Tag[]|null * @SerializedName("tags") - * @Assert\All({ - * @Assert\Type("OpenAPI\Server\Model\Tag") - * }) * @Type("array") - */ + */ + #[Assert\All([ + new Assert\Type("OpenAPI\Server\Model\Tag"), + ])] protected ?array $tags = null; /** @@ -96,10 +96,10 @@ class Pet * * @var string|null * @SerializedName("status") - * @Assert\Choice({ "available", "pending", "sold" }) - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Choice(["available", "pending", "sold"])] + #[Assert\Type("string")] protected ?string $status = null; /** @@ -128,15 +128,13 @@ public function getId(): ?int return $this->id; } - - /** - * Sets id. - * - * @param int|null $id - * - * @return $this - */ + * Sets id. + * + * @param int|null $id + * + * @return $this + */ public function setId(?int $id = null): self { $this->id = $id; @@ -144,6 +142,9 @@ public function setId(?int $id = null): self return $this; } + + + /** * Gets category. * @@ -154,15 +155,13 @@ public function getCategory(): ?Category return $this->category; } - - /** - * Sets category. - * - * @param Category|null $category - * - * @return $this - */ + * Sets category. + * + * @param Category|null $category + * + * @return $this + */ public function setCategory(?Category $category = null): self { $this->category = $category; @@ -170,6 +169,9 @@ public function setCategory(?Category $category = null): self return $this; } + + + /** * Gets name. * @@ -180,15 +182,13 @@ public function getName(): ?string return $this->name; } - - /** - * Sets name. - * - * @param string|null $name - * - * @return $this - */ + * Sets name. + * + * @param string|null $name + * + * @return $this + */ public function setName(?string $name): self { $this->name = $name; @@ -196,6 +196,9 @@ public function setName(?string $name): self return $this; } + + + /** * Gets photoUrls. * @@ -206,15 +209,13 @@ public function getPhotoUrls(): ?array return $this->photoUrls; } - - /** - * Sets photoUrls. - * - * @param string[]|null $photoUrls - * - * @return $this - */ + * Sets photoUrls. + * + * @param string[]|null $photoUrls + * + * @return $this + */ public function setPhotoUrls(?array $photoUrls): self { $this->photoUrls = $photoUrls; @@ -222,6 +223,9 @@ public function setPhotoUrls(?array $photoUrls): self return $this; } + + + /** * Gets tags. * @@ -232,15 +236,13 @@ public function getTags(): ?array return $this->tags; } - - /** - * Sets tags. - * - * @param Tag[]|null $tags - * - * @return $this - */ + * Sets tags. + * + * @param Tag[]|null $tags + * + * @return $this + */ public function setTags(?array $tags = null): self { $this->tags = $tags; @@ -248,6 +250,9 @@ public function setTags(?array $tags = null): self return $this; } + + + /** * Gets status. * @@ -258,21 +263,22 @@ public function getStatus(): ?string return $this->status; } - - /** - * Sets status. - * - * @param string|null $status pet status in the store - * - * @return $this - */ + * Sets status. + * + * @param string|null $status pet status in the store + * + * @return $this + */ public function setStatus(?string $status = null): self { $this->status = $status; return $this; } + + + } 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 5c242dff5370..7d669ab9bb07 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -48,17 +48,17 @@ class Tag /** * @var int|null * @SerializedName("id") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $id = null; /** * @var string|null * @SerializedName("name") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $name = null; /** @@ -83,15 +83,13 @@ public function getId(): ?int return $this->id; } - - /** - * Sets id. - * - * @param int|null $id - * - * @return $this - */ + * Sets id. + * + * @param int|null $id + * + * @return $this + */ public function setId(?int $id = null): self { $this->id = $id; @@ -99,6 +97,9 @@ public function setId(?int $id = null): self return $this; } + + + /** * Gets name. * @@ -109,21 +110,22 @@ public function getName(): ?string return $this->name; } - - /** - * Sets name. - * - * @param string|null $name - * - * @return $this - */ + * Sets name. + * + * @param string|null $name + * + * @return $this + */ public function setName(?string $name = null): self { $this->name = $name; return $this; } + + + } 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 db11613de25e..b15d7fef65d8 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -48,57 +48,57 @@ class User /** * @var int|null * @SerializedName("id") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $id = null; /** * @var string|null * @SerializedName("username") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $username = null; /** * @var string|null * @SerializedName("firstName") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $firstName = null; /** * @var string|null * @SerializedName("lastName") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $lastName = null; /** * @var string|null * @SerializedName("email") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $email = null; /** * @var string|null * @SerializedName("password") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $password = null; /** * @var string|null * @SerializedName("phone") - * @Assert\Type("string") * @Type("string") - */ + */ + #[Assert\Type("string")] protected ?string $phone = null; /** @@ -106,9 +106,9 @@ class User * * @var int|null * @SerializedName("userStatus") - * @Assert\Type("int") * @Type("int") - */ + */ + #[Assert\Type("int")] protected ?int $userStatus = null; /** @@ -139,15 +139,13 @@ public function getId(): ?int return $this->id; } - - /** - * Sets id. - * - * @param int|null $id - * - * @return $this - */ + * Sets id. + * + * @param int|null $id + * + * @return $this + */ public function setId(?int $id = null): self { $this->id = $id; @@ -155,6 +153,9 @@ public function setId(?int $id = null): self return $this; } + + + /** * Gets username. * @@ -165,15 +166,13 @@ public function getUsername(): ?string return $this->username; } - - /** - * Sets username. - * - * @param string|null $username - * - * @return $this - */ + * Sets username. + * + * @param string|null $username + * + * @return $this + */ public function setUsername(?string $username = null): self { $this->username = $username; @@ -181,6 +180,9 @@ public function setUsername(?string $username = null): self return $this; } + + + /** * Gets firstName. * @@ -191,15 +193,13 @@ public function getFirstName(): ?string return $this->firstName; } - - /** - * Sets firstName. - * - * @param string|null $firstName - * - * @return $this - */ + * Sets firstName. + * + * @param string|null $firstName + * + * @return $this + */ public function setFirstName(?string $firstName = null): self { $this->firstName = $firstName; @@ -207,6 +207,9 @@ public function setFirstName(?string $firstName = null): self return $this; } + + + /** * Gets lastName. * @@ -217,15 +220,13 @@ public function getLastName(): ?string return $this->lastName; } - - /** - * Sets lastName. - * - * @param string|null $lastName - * - * @return $this - */ + * Sets lastName. + * + * @param string|null $lastName + * + * @return $this + */ public function setLastName(?string $lastName = null): self { $this->lastName = $lastName; @@ -233,6 +234,9 @@ public function setLastName(?string $lastName = null): self return $this; } + + + /** * Gets email. * @@ -243,15 +247,13 @@ public function getEmail(): ?string return $this->email; } - - /** - * Sets email. - * - * @param string|null $email - * - * @return $this - */ + * Sets email. + * + * @param string|null $email + * + * @return $this + */ public function setEmail(?string $email = null): self { $this->email = $email; @@ -259,6 +261,9 @@ public function setEmail(?string $email = null): self return $this; } + + + /** * Gets password. * @@ -269,15 +274,13 @@ public function getPassword(): ?string return $this->password; } - - /** - * Sets password. - * - * @param string|null $password - * - * @return $this - */ + * Sets password. + * + * @param string|null $password + * + * @return $this + */ public function setPassword(?string $password = null): self { $this->password = $password; @@ -285,6 +288,9 @@ public function setPassword(?string $password = null): self return $this; } + + + /** * Gets phone. * @@ -295,15 +301,13 @@ public function getPhone(): ?string return $this->phone; } - - /** - * Sets phone. - * - * @param string|null $phone - * - * @return $this - */ + * Sets phone. + * + * @param string|null $phone + * + * @return $this + */ public function setPhone(?string $phone = null): self { $this->phone = $phone; @@ -311,6 +315,9 @@ public function setPhone(?string $phone = null): self return $this; } + + + /** * Gets userStatus. * @@ -321,21 +328,22 @@ public function getUserStatus(): ?int return $this->userStatus; } - - /** - * Sets userStatus. - * - * @param int|null $userStatus User Status - * - * @return $this - */ + * Sets userStatus. + * + * @param int|null $userStatus User Status + * + * @return $this + */ public function setUserStatus(?int $userStatus = null): self { $this->userStatus = $userStatus; return $this; } + + + } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php index 12c69bab088b..5abbc6de3fb9 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Service/JmsSerializer.php @@ -101,12 +101,16 @@ private function deserializeString($data, string $type) case '\DateTime': return is_null($data) ? null :new DateTime($data); default: + if (is_null($data)) { + return null; + } + if (!class_exists($type)) { throw new RuntimeException(sprintf("Type %s is unsupported", $type)); } $reflectionClass = new \ReflectionClass($type); - if (!$reflectionClass->implementsInterface('\BackedENum')) { + if (!$reflectionClass->implementsInterface('\BackedEnum')) { throw new RuntimeException(sprintf("Type %s is unsupported", $type)); } diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json b/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json index 258c66371039..fdce9d5c69c3 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/composer.json @@ -20,6 +20,7 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", + "doctrine/annotations": "^2.0", "symfony/validator": "^6.4|^7.0", "jms/serializer-bundle": "^5.4", "symfony/framework-bundle": "^6.4|^7.0"