Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enum name mapping support to PHP generators #17195

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading