From 84ff214c96ae24e2b380d577b16337fbfad15a60 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 27 Nov 2023 15:51:44 +0800 Subject: [PATCH] add enum name mapping support to php generators --- bin/configs/php-nextgen.yaml | 2 ++ .../codegen/languages/AbstractPhpCodegen.java | 8 ++++++++ .../php-nextgen/OpenAPIClient-php/src/Model/Order.php | 4 ++-- .../php-nextgen/OpenAPIClient-php/src/Model/OuterEnum.php | 2 +- .../OpenAPIClient-php/src/Model/OuterEnumDefaultValue.php | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/configs/php-nextgen.yaml b/bin/configs/php-nextgen.yaml index e8db9d729c2d..ed0f8bfd99db 100644 --- a/bin/configs/php-nextgen.yaml +++ b/bin/configs/php-nextgen.yaml @@ -2,3 +2,5 @@ generatorName: php-nextgen outputDir: samples/client/petstore/php-nextgen/OpenAPIClient-php inputSpec: modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml templateDir: modules/openapi-generator/src/main/resources/php-nextgen +enumNameMappings: + delivered: SHIPPED diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index c4815a6557a0..19dddf4a3715 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -742,6 +742,10 @@ public String toEnumDefaultValue(String value, String datatype) { @Override public String toEnumVarName(String name, String datatype) { + if (enumNameMapping.containsKey(name)) { + return enumNameMapping.get(name); + } + if (name.length() == 0) { return "EMPTY"; } @@ -778,6 +782,10 @@ public String toEnumVarName(String name, String datatype) { @Override public String toEnumName(CodegenProperty property) { + if (enumNameMapping.containsKey(property.name)) { + return enumNameMapping.get(property.name); + } + String enumName = underscore(toGenericName(property.name)).toUpperCase(Locale.ROOT); // remove [] for array or map of enum diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Order.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Order.php index 058f369873f7..3e953e64c602 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Order.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/Order.php @@ -259,7 +259,7 @@ public function getModelName(): string public const STATUS_PLACED = 'placed'; public const STATUS_APPROVED = 'approved'; - public const STATUS_DELIVERED = 'delivered'; + public const STATUS_SHIPPED = 'delivered'; /** * Gets allowable values of the enum @@ -271,7 +271,7 @@ public function getStatusAllowableValues() return [ self::STATUS_PLACED, self::STATUS_APPROVED, - self::STATUS_DELIVERED, + self::STATUS_SHIPPED, ]; } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnum.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnum.php index 8d70bd7df90e..0cdae8ad6cd5 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnum.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnum.php @@ -40,7 +40,7 @@ enum OuterEnum: string case APPROVED = 'approved'; - case DELIVERED = 'delivered'; + case SHIPPED = 'delivered'; } diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnumDefaultValue.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnumDefaultValue.php index 938b78079b76..58b609135ee0 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnumDefaultValue.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/OuterEnumDefaultValue.php @@ -40,7 +40,7 @@ enum OuterEnumDefaultValue: string case APPROVED = 'approved'; - case DELIVERED = 'delivered'; + case SHIPPED = 'delivered'; }