From efdc94b113e7a227b40bf554c83821a95d8448c4 Mon Sep 17 00:00:00 2001 From: renaud-twd <78761895+renaud-twd@users.noreply.github.com> Date: Tue, 27 Dec 2022 05:42:41 -1000 Subject: [PATCH] Fix enum generation for php-symfony generator (#14105) * fix(symfony): enum generation * docs(php symfony): update samples and docs --- .../main/resources/php-symfony/model.mustache | 3 ++- .../SymfonyBundle-php/Model/ApiResponse.php | 1 + .../SymfonyBundle-php/Model/Category.php | 1 + .../Model/EnumStringModel.php | 23 +++++++++++++++---- .../SymfonyBundle-php/Model/Order.php | 1 + .../SymfonyBundle-php/Model/Pet.php | 1 + .../SymfonyBundle-php/Model/Tag.php | 1 + .../SymfonyBundle-php/Model/User.php | 1 + 8 files changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-symfony/model.mustache b/modules/openapi-generator/src/main/resources/php-symfony/model.mustache index 2435f607663a..ec0e23540ab6 100644 --- a/modules/openapi-generator/src/main/resources/php-symfony/model.mustache +++ b/modules/openapi-generator/src/main/resources/php-symfony/model.mustache @@ -35,5 +35,6 @@ use JMS\Serializer\Annotation\SerializedName; * @package {{modelPackage}} * @author OpenAPI Generator team */ -{{>model_generic}} +{{#isEnum}}{{>model_enum}}{{/isEnum}} +{{^isEnum}}{{>model_generic}}{{/isEnum}} {{/model}}{{/models}} 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 174fd7969e33..21b86eeae337 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/ApiResponse.php @@ -41,6 +41,7 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ + class ApiResponse { /** 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 0175e84a1b2c..fac8878d4644 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Category.php @@ -41,6 +41,7 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ + class Category { /** diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/EnumStringModel.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/EnumStringModel.php index c2bffa585265..d637e27af2fb 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/EnumStringModel.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/EnumStringModel.php @@ -41,15 +41,28 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ -class EnumStringModel +class EnumStringModel { - /** - * Constructor - * @param array|null $data Associated array of property values initializing the model + /** + * Possible values of this enum */ - public function __construct(array $data = null) + const AVAILABLE = "available"; + const PENDING = "pending"; + const SOLD = "sold"; + + /** + * Gets allowable values of the enum + * @return string[] + */ + public static function getAllowableEnumValues() { + return [ + self::AVAILABLE, + self::PENDING, + self::SOLD, + ]; } } + 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 9ebeb0a1f57a..72c6a15db0dc 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Order.php @@ -41,6 +41,7 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ + class Order { /** 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 3e3aa07a6899..6a400e7c2486 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Pet.php @@ -41,6 +41,7 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ + class Pet { /** 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 fb60b40200df..3ee1398a4840 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/Tag.php @@ -41,6 +41,7 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ + class Tag { /** 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 8765a4e389ed..179ec3f173b6 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Model/User.php @@ -41,6 +41,7 @@ * @package OpenAPI\Server\Model * @author OpenAPI Generator team */ + class User { /**