[PHP] Enhance Symfony generator (#12532)

* Enhance Symfony generator

  - Add missing typehints
  - Add missing use statements
  - Simplify model ctor
  - Change fallthrough Exception to Throwable
  - prevent storing result of void methods
  - fix validate method
  - add default null values to model properties
  - simplify API interface return values
  - fix/rework default value implementation
  - fix optional params deprecation warnings
  - ..

For more details check out the PR: https://github.com/OpenAPITools/openapi-generator/pull/12532

* Enhance Symfony generator Tests

  - Skip risky tests
  - Fix type hint error
  - Fix class exists tests
  - Fix broken doc block
  - Enhance annotations
  - Update phpunit.xml.dist
  - Fix test config resource location
This commit is contained in:
Daniel Metzner
2022-06-25 14:53:21 +02:00
committed by GitHub
parent 286a31c019
commit 3b15bb8a4e
56 changed files with 862 additions and 558 deletions

View File

@@ -49,7 +49,7 @@ class ApiResponse
* @Assert\Type("int")
* @Type("int")
*/
protected $code;
protected ?int $code = null;
/**
* @var string|null
@@ -57,7 +57,7 @@ class ApiResponse
* @Assert\Type("string")
* @Type("string")
*/
protected $type;
protected ?string $type = null;
/**
* @var string|null
@@ -65,17 +65,17 @@ class ApiResponse
* @Assert\Type("string")
* @Type("string")
*/
protected $message;
protected ?string $message = null;
/**
* Constructor
* @param mixed[] $data Associated array of property values initializing the model
* @param array|null $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
$this->code = isset($data['code']) ? $data['code'] : null;
$this->type = isset($data['type']) ? $data['type'] : null;
$this->message = isset($data['message']) ? $data['message'] : null;
$this->code = $data['code'] ?? null;
$this->type = $data['type'] ?? null;
$this->message = $data['message'] ?? null;
}
/**
@@ -83,7 +83,7 @@ class ApiResponse
*
* @return int|null
*/
public function getCode()
public function getCode(): ?int
{
return $this->code;
}
@@ -95,7 +95,7 @@ class ApiResponse
*
* @return $this
*/
public function setCode($code = null)
public function setCode(?int $code = null): self
{
$this->code = $code;
@@ -107,7 +107,7 @@ class ApiResponse
*
* @return string|null
*/
public function getType()
public function getType(): ?string
{
return $this->type;
}
@@ -119,7 +119,7 @@ class ApiResponse
*
* @return $this
*/
public function setType($type = null)
public function setType(?string $type = null): self
{
$this->type = $type;
@@ -131,7 +131,7 @@ class ApiResponse
*
* @return string|null
*/
public function getMessage()
public function getMessage(): ?string
{
return $this->message;
}
@@ -143,7 +143,7 @@ class ApiResponse
*
* @return $this
*/
public function setMessage($message = null)
public function setMessage(?string $message = null): self
{
$this->message = $message;

View File

@@ -49,7 +49,7 @@ class Category
* @Assert\Type("int")
* @Type("int")
*/
protected $id;
protected ?int $id = null;
/**
* @var string|null
@@ -58,16 +58,16 @@ class Category
* @Type("string")
* @Assert\Regex("/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/")
*/
protected $name;
protected ?string $name = null;
/**
* Constructor
* @param mixed[] $data Associated array of property values initializing the model
* @param array|null $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
$this->id = isset($data['id']) ? $data['id'] : null;
$this->name = isset($data['name']) ? $data['name'] : null;
$this->id = $data['id'] ?? null;
$this->name = $data['name'] ?? null;
}
/**
@@ -75,7 +75,7 @@ class Category
*
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -87,7 +87,7 @@ class Category
*
* @return $this
*/
public function setId($id = null)
public function setId(?int $id = null): self
{
$this->id = $id;
@@ -99,7 +99,7 @@ class Category
*
* @return string|null
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
@@ -111,7 +111,7 @@ class Category
*
* @return $this
*/
public function setName($name = null)
public function setName(?string $name = null): self
{
$this->name = $name;

View File

@@ -49,7 +49,7 @@ class Order
* @Assert\Type("int")
* @Type("int")
*/
protected $id;
protected ?int $id = null;
/**
* @var int|null
@@ -57,7 +57,7 @@ class Order
* @Assert\Type("int")
* @Type("int")
*/
protected $petId;
protected ?int $petId = null;
/**
* @var int|null
@@ -65,7 +65,7 @@ class Order
* @Assert\Type("int")
* @Type("int")
*/
protected $quantity;
protected ?int $quantity = null;
/**
* @var \DateTime|null
@@ -73,7 +73,7 @@ class Order
* @Assert\DateTime()
* @Type("DateTime")
*/
protected $shipDate;
protected ?\DateTime $shipDate = null;
/**
* Order Status
@@ -84,7 +84,7 @@ class Order
* @Assert\Type("string")
* @Type("string")
*/
protected $status;
protected ?string $status = null;
/**
* @var bool|null
@@ -92,20 +92,20 @@ class Order
* @Assert\Type("bool")
* @Type("bool")
*/
protected $complete;
protected ?bool $complete = null;
/**
* Constructor
* @param mixed[] $data Associated array of property values initializing the model
* @param array|null $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
$this->id = isset($data['id']) ? $data['id'] : null;
$this->petId = isset($data['petId']) ? $data['petId'] : null;
$this->quantity = isset($data['quantity']) ? $data['quantity'] : null;
$this->shipDate = isset($data['shipDate']) ? $data['shipDate'] : null;
$this->status = isset($data['status']) ? $data['status'] : null;
$this->complete = isset($data['complete']) ? $data['complete'] : false;
$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;
}
/**
@@ -113,7 +113,7 @@ class Order
*
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -125,7 +125,7 @@ class Order
*
* @return $this
*/
public function setId($id = null)
public function setId(?int $id = null): self
{
$this->id = $id;
@@ -137,7 +137,7 @@ class Order
*
* @return int|null
*/
public function getPetId()
public function getPetId(): ?int
{
return $this->petId;
}
@@ -149,7 +149,7 @@ class Order
*
* @return $this
*/
public function setPetId($petId = null)
public function setPetId(?int $petId = null): self
{
$this->petId = $petId;
@@ -161,7 +161,7 @@ class Order
*
* @return int|null
*/
public function getQuantity()
public function getQuantity(): ?int
{
return $this->quantity;
}
@@ -173,7 +173,7 @@ class Order
*
* @return $this
*/
public function setQuantity($quantity = null)
public function setQuantity(?int $quantity = null): self
{
$this->quantity = $quantity;
@@ -197,7 +197,7 @@ class Order
*
* @return $this
*/
public function setShipDate(\DateTime $shipDate = null)
public function setShipDate(?\DateTime $shipDate = null): self
{
$this->shipDate = $shipDate;
@@ -209,7 +209,7 @@ class Order
*
* @return string|null
*/
public function getStatus()
public function getStatus(): ?string
{
return $this->status;
}
@@ -221,7 +221,7 @@ class Order
*
* @return $this
*/
public function setStatus($status = null)
public function setStatus(?string $status = null): self
{
$this->status = $status;
@@ -233,7 +233,7 @@ class Order
*
* @return bool|null
*/
public function isComplete()
public function isComplete(): ?bool
{
return $this->complete;
}
@@ -245,7 +245,7 @@ class Order
*
* @return $this
*/
public function setComplete($complete = null)
public function setComplete(?bool $complete = null): self
{
$this->complete = $complete;

View File

@@ -49,27 +49,27 @@ class Pet
* @Assert\Type("int")
* @Type("int")
*/
protected $id;
protected ?int $id = null;
/**
* @var OpenAPI\Server\Model\Category|null
* @var Category|null
* @SerializedName("category")
* @Assert\Type("OpenAPI\Server\Model\Category")
* @Type("OpenAPI\Server\Model\Category")
*/
protected $category;
protected ?Category $category = null;
/**
* @var string
* @var string|null
* @SerializedName("name")
* @Assert\NotNull()
* @Assert\Type("string")
* @Type("string")
*/
protected $name;
protected ?string $name = null;
/**
* @var string[]
* @var array|null
* @SerializedName("photoUrls")
* @Assert\NotNull()
* @Assert\All({
@@ -77,17 +77,17 @@ class Pet
* })
* @Type("array<string>")
*/
protected $photoUrls;
protected ?array $photoUrls = null;
/**
* @var OpenAPI\Server\Model\Tag[]|null
* @var array|null
* @SerializedName("tags")
* @Assert\All({
* @Assert\Type("OpenAPI\Server\Model\Tag")
* })
* @Type("array<OpenAPI\Server\Model\Tag>")
*/
protected $tags;
protected ?array $tags = null;
/**
* pet status in the store
@@ -98,20 +98,20 @@ class Pet
* @Assert\Type("string")
* @Type("string")
*/
protected $status;
protected ?string $status = null;
/**
* Constructor
* @param mixed[] $data Associated array of property values initializing the model
* @param array|null $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
$this->id = isset($data['id']) ? $data['id'] : null;
$this->category = isset($data['category']) ? $data['category'] : null;
$this->name = isset($data['name']) ? $data['name'] : null;
$this->photoUrls = isset($data['photoUrls']) ? $data['photoUrls'] : null;
$this->tags = isset($data['tags']) ? $data['tags'] : null;
$this->status = isset($data['status']) ? $data['status'] : 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;
}
/**
@@ -119,7 +119,7 @@ class Pet
*
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -131,7 +131,7 @@ class Pet
*
* @return $this
*/
public function setId($id = null)
public function setId(?int $id = null): self
{
$this->id = $id;
@@ -141,7 +141,7 @@ class Pet
/**
* Gets category.
*
* @return OpenAPI\Server\Model\Category|null
* @return Category|null
*/
public function getCategory(): ?Category
{
@@ -151,11 +151,11 @@ class Pet
/**
* Sets category.
*
* @param OpenAPI\Server\Model\Category|null $category
* @param Category|null $category
*
* @return $this
*/
public function setCategory(Category $category = null)
public function setCategory(?Category $category = null): self
{
$this->category = $category;
@@ -165,9 +165,9 @@ class Pet
/**
* Gets name.
*
* @return string
* @return string|null
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
@@ -175,11 +175,11 @@ class Pet
/**
* Sets name.
*
* @param string $name
* @param string|null $name
*
* @return $this
*/
public function setName($name)
public function setName(?string $name): self
{
$this->name = $name;
@@ -189,9 +189,9 @@ class Pet
/**
* Gets photoUrls.
*
* @return string[]
* @return array|null
*/
public function getPhotoUrls(): array
public function getPhotoUrls(): ?array
{
return $this->photoUrls;
}
@@ -199,11 +199,11 @@ class Pet
/**
* Sets photoUrls.
*
* @param string[] $photoUrls
* @param array|null $photoUrls
*
* @return $this
*/
public function setPhotoUrls(array $photoUrls)
public function setPhotoUrls(?array $photoUrls): self
{
$this->photoUrls = $photoUrls;
@@ -213,7 +213,7 @@ class Pet
/**
* Gets tags.
*
* @return OpenAPI\Server\Model\Tag[]|null
* @return array|null
*/
public function getTags(): ?array
{
@@ -223,11 +223,11 @@ class Pet
/**
* Sets tags.
*
* @param OpenAPI\Server\Model\Tag[]|null $tags
* @param array|null $tags
*
* @return $this
*/
public function setTags(array $tags = null)
public function setTags(?array $tags = null): self
{
$this->tags = $tags;
@@ -239,7 +239,7 @@ class Pet
*
* @return string|null
*/
public function getStatus()
public function getStatus(): ?string
{
return $this->status;
}
@@ -251,7 +251,7 @@ class Pet
*
* @return $this
*/
public function setStatus($status = null)
public function setStatus(?string $status = null): self
{
$this->status = $status;

View File

@@ -49,7 +49,7 @@ class Tag
* @Assert\Type("int")
* @Type("int")
*/
protected $id;
protected ?int $id = null;
/**
* @var string|null
@@ -57,16 +57,16 @@ class Tag
* @Assert\Type("string")
* @Type("string")
*/
protected $name;
protected ?string $name = null;
/**
* Constructor
* @param mixed[] $data Associated array of property values initializing the model
* @param array|null $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
$this->id = isset($data['id']) ? $data['id'] : null;
$this->name = isset($data['name']) ? $data['name'] : null;
$this->id = $data['id'] ?? null;
$this->name = $data['name'] ?? null;
}
/**
@@ -74,7 +74,7 @@ class Tag
*
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -86,7 +86,7 @@ class Tag
*
* @return $this
*/
public function setId($id = null)
public function setId(?int $id = null): self
{
$this->id = $id;
@@ -98,7 +98,7 @@ class Tag
*
* @return string|null
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
@@ -110,7 +110,7 @@ class Tag
*
* @return $this
*/
public function setName($name = null)
public function setName(?string $name = null): self
{
$this->name = $name;

View File

@@ -49,7 +49,7 @@ class User
* @Assert\Type("int")
* @Type("int")
*/
protected $id;
protected ?int $id = null;
/**
* @var string|null
@@ -57,7 +57,7 @@ class User
* @Assert\Type("string")
* @Type("string")
*/
protected $username;
protected ?string $username = null;
/**
* @var string|null
@@ -65,7 +65,7 @@ class User
* @Assert\Type("string")
* @Type("string")
*/
protected $firstName;
protected ?string $firstName = null;
/**
* @var string|null
@@ -73,7 +73,7 @@ class User
* @Assert\Type("string")
* @Type("string")
*/
protected $lastName;
protected ?string $lastName = null;
/**
* @var string|null
@@ -81,7 +81,7 @@ class User
* @Assert\Type("string")
* @Type("string")
*/
protected $email;
protected ?string $email = null;
/**
* @var string|null
@@ -89,7 +89,7 @@ class User
* @Assert\Type("string")
* @Type("string")
*/
protected $password;
protected ?string $password = null;
/**
* @var string|null
@@ -97,7 +97,7 @@ class User
* @Assert\Type("string")
* @Type("string")
*/
protected $phone;
protected ?string $phone = null;
/**
* User Status
@@ -107,22 +107,22 @@ class User
* @Assert\Type("int")
* @Type("int")
*/
protected $userStatus;
protected ?int $userStatus = null;
/**
* Constructor
* @param mixed[] $data Associated array of property values initializing the model
* @param array|null $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
$this->id = isset($data['id']) ? $data['id'] : null;
$this->username = isset($data['username']) ? $data['username'] : null;
$this->firstName = isset($data['firstName']) ? $data['firstName'] : null;
$this->lastName = isset($data['lastName']) ? $data['lastName'] : null;
$this->email = isset($data['email']) ? $data['email'] : null;
$this->password = isset($data['password']) ? $data['password'] : null;
$this->phone = isset($data['phone']) ? $data['phone'] : null;
$this->userStatus = isset($data['userStatus']) ? $data['userStatus'] : 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;
}
/**
@@ -130,7 +130,7 @@ class User
*
* @return int|null
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -142,7 +142,7 @@ class User
*
* @return $this
*/
public function setId($id = null)
public function setId(?int $id = null): self
{
$this->id = $id;
@@ -154,7 +154,7 @@ class User
*
* @return string|null
*/
public function getUsername()
public function getUsername(): ?string
{
return $this->username;
}
@@ -166,7 +166,7 @@ class User
*
* @return $this
*/
public function setUsername($username = null)
public function setUsername(?string $username = null): self
{
$this->username = $username;
@@ -178,7 +178,7 @@ class User
*
* @return string|null
*/
public function getFirstName()
public function getFirstName(): ?string
{
return $this->firstName;
}
@@ -190,7 +190,7 @@ class User
*
* @return $this
*/
public function setFirstName($firstName = null)
public function setFirstName(?string $firstName = null): self
{
$this->firstName = $firstName;
@@ -202,7 +202,7 @@ class User
*
* @return string|null
*/
public function getLastName()
public function getLastName(): ?string
{
return $this->lastName;
}
@@ -214,7 +214,7 @@ class User
*
* @return $this
*/
public function setLastName($lastName = null)
public function setLastName(?string $lastName = null): self
{
$this->lastName = $lastName;
@@ -226,7 +226,7 @@ class User
*
* @return string|null
*/
public function getEmail()
public function getEmail(): ?string
{
return $this->email;
}
@@ -238,7 +238,7 @@ class User
*
* @return $this
*/
public function setEmail($email = null)
public function setEmail(?string $email = null): self
{
$this->email = $email;
@@ -250,7 +250,7 @@ class User
*
* @return string|null
*/
public function getPassword()
public function getPassword(): ?string
{
return $this->password;
}
@@ -262,7 +262,7 @@ class User
*
* @return $this
*/
public function setPassword($password = null)
public function setPassword(?string $password = null): self
{
$this->password = $password;
@@ -274,7 +274,7 @@ class User
*
* @return string|null
*/
public function getPhone()
public function getPhone(): ?string
{
return $this->phone;
}
@@ -286,7 +286,7 @@ class User
*
* @return $this
*/
public function setPhone($phone = null)
public function setPhone(?string $phone = null): self
{
$this->phone = $phone;
@@ -298,7 +298,7 @@ class User
*
* @return int|null
*/
public function getUserStatus()
public function getUserStatus(): ?int
{
return $this->userStatus;
}
@@ -310,7 +310,7 @@ class User
*
* @return $this
*/
public function setUserStatus($userStatus = null)
public function setUserStatus(?int $userStatus = null): self
{
$this->userStatus = $userStatus;