Skip to content

[BUG][php-nextgen] ObjectSerializer methods fail with enums as parameters #20086

Description

@DisasterCoding

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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
  • my config.json
   {
   "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
  1. Use the above command with the OpenAPI spec and the modified template.
  2. 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}}
);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions