add enum name mapping support to php generators (#17195)

This commit is contained in:
William Cheng 2023-11-27 20:26:28 +08:00 committed by GitHub
parent ac687657ba
commit e2a8118c86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -742,6 +742,10 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
@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 abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
@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

View File

@ -259,7 +259,7 @@ class Order implements ModelInterface, ArrayAccess, JsonSerializable
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 @@ class Order implements ModelInterface, ArrayAccess, JsonSerializable
return [
self::STATUS_PLACED,
self::STATUS_APPROVED,
self::STATUS_DELIVERED,
self::STATUS_SHIPPED,
];
}

View File

@ -40,7 +40,7 @@ enum OuterEnum: string
case APPROVED = 'approved';
case DELIVERED = 'delivered';
case SHIPPED = 'delivered';
}

View File

@ -40,7 +40,7 @@ enum OuterEnumDefaultValue: string
case APPROVED = 'approved';
case DELIVERED = 'delivered';
case SHIPPED = 'delivered';
}