swagger-codegen
swagger-codegen copied to clipboard
[PHP] Enum with type integer creates invalid const names
Description
When a model is generated for a schema defined as an enum with type integer a class constant is included for each value. These constants will use the integer value as their name which is not valid PHP. For enums with type string the names for numeric values seem to be prefixed with _ but this does not happen for type integer.
Swagger-codegen version
3.0.30
Swagger declaration file content or url
The following schema definition:
"ResponseCode": {
"enum": [
1,
2
],
"type": "integer",
"format": "int32"
}
Results in:
class ResponseCode
{
/**
* Possible values of this enum
*/
const 1 = 1;
const 2 = 2;
/**
* Gets allowable values of the enum
* @return string[]
*/
public static function getAllowableEnumValues()
{
return [
self::1,
self::2, ];
}
}
While the following schema definition:
"ResponseCode": {
"enum": [
"1",
"2"
],
"type": "string"
}
Results in:
class ResponseCode
{
/**
* Possible values of this enum
*/
const _1 = '1';
const _2 = '2';
/**
* Gets allowable values of the enum
* @return string[]
*/
public static function getAllowableEnumValues()
{
return [
self::_1,
self::_2, ];
}
}
Hi @paulvandermeijs, I'm running into the same issue with a PHP client that was generated by Swagger Codegen. Did you find any workaround to correct this without having to manually change each one of these?