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

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

Closed
4 of 6 tasks
DisasterCoding opened this issue Nov 12, 2024 · 1 comment
Closed
4 of 6 tasks

Comments

@DisasterCoding
Copy link

DisasterCoding commented Nov 12, 2024

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}}
);
@JulianVennen
Copy link
Contributor

This is fixed by #20294

@wing328 wing328 closed this as completed Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants