Skip to content

Commit

Permalink
add enum name mapping support to php generators (#17195)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Nov 27, 2023
1 parent ac68765 commit e2a8118
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bin/configs/php-nextgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -271,7 +271,7 @@ public function getStatusAllowableValues()
return [
self::STATUS_PLACED,
self::STATUS_APPROVED,
self::STATUS_DELIVERED,
self::STATUS_SHIPPED,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum OuterEnum: string

case APPROVED = 'approved';

case DELIVERED = 'delivered';
case SHIPPED = 'delivered';

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum OuterEnumDefaultValue: string

case APPROVED = 'approved';

case DELIVERED = 'delivered';
case SHIPPED = 'delivered';

}

Expand Down

0 comments on commit e2a8118

Please sign in to comment.