Bug Report Checklist
Description
When using ObjectSerializer methods, an exception occurs because parameters passed are enums instead of strings. This error arises in several methods, which require checking if parameters are enums and using their values directly.
openapi-generator version
7.9.0
OpenAPI declaration file content or URL
The issue can be observed in the api.mustache file at:
OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-nextgen/api.mustache
Lines 714, 731, and other relevant sections have been modified to check if parameters are enums and to use their values, like this:
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
${{paramName}} instanceof \BackedEnum ? ${{paramName}}->value : ${{paramName}},
'{{baseName}}', // param base name
'{{#schema}}{{openApiType}}{{/schema}}', // openApiType
'{{style}}', // style
{{#isExplode}}true{{/isExplode}}{{^isExplode}}false{{/isExplode}}, // explode
{{required}} // required
) ?? []);
Generation Details
{
"invokerPackage": "Project",
"disallowAdditionalPropertiesIfNotPresent": false,
"legacyDiscriminatorBehavior": false,
"prependFormOrBodyParameters": true,
"variableNamingConvention": "camelCase",
"phpLegacySupport": false,
"booleanGetterPrefix": "is"
}
- then I made changes to the api.mustache template
- cli
openapi-generator generate -i project.yaml -g php-nextgen -o project -c config.json -t templates
Steps to reproduce
- Use the above command with the OpenAPI spec and the modified template.
- Attempt to generate code and note the instances where enums cause exceptions due to improper handling by
ObjectSerializer methods.
Related issues/PRs
- No related issues/PRs found.
Suggest a fix
Update relevant ObjectSerializer method calls to check if paramName is an enum, and if so, use paramName->value.
For instance:
$headerParams['{{baseName}}'] = ObjectSerializer::toHeaderValue(
${{paramName}} instanceof \BackedEnum ? ${{paramName}}->value : ${{paramName}}
);
Bug Report Checklist
Description
When using
ObjectSerializermethods, an exception occurs because parameters passed are enums instead of strings. This error arises in several methods, which require checking if parameters are enums and using their values directly.openapi-generator version
7.9.0
OpenAPI declaration file content or URL
The issue can be observed in the
api.mustachefile at:OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/php-nextgen/api.mustacheLines 714, 731, and other relevant sections have been modified to check if parameters are enums and to use their values, like this:
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( ${{paramName}} instanceof \BackedEnum ? ${{paramName}}->value : ${{paramName}}, '{{baseName}}', // param base name '{{#schema}}{{openApiType}}{{/schema}}', // openApiType '{{style}}', // style {{#isExplode}}true{{/isExplode}}{{^isExplode}}false{{/isExplode}}, // explode {{required}} // required ) ?? []);Generation Details
{ "invokerPackage": "Project", "disallowAdditionalPropertiesIfNotPresent": false, "legacyDiscriminatorBehavior": false, "prependFormOrBodyParameters": true, "variableNamingConvention": "camelCase", "phpLegacySupport": false, "booleanGetterPrefix": "is" }Steps to reproduce
ObjectSerializermethods.Related issues/PRs
Suggest a fix
Update relevant
ObjectSerializermethod calls to check ifparamNameis an enum, and if so, useparamName->value.For instance: