Skip to content

[BUG][php-nextgen] query parameters with array enum type are not serialized correctly #22319

@JulianVennen

Description

@JulianVennen

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

If you have an API endpoint that accepts a query paramter which is an array of enum values, they are not serialized correctly and the following exception is thrown:

PHP Fatal error:  Uncaught Error: Object of class OpenAPI\Client\Model\Enum could not be converted to string in /home/julian/workspace/tmp/openapi-enum-params/src/ObjectSerializer.php:583
Stack trace:
#0 /home/julian/workspace/tmp/openapi-enum-params/src/Api/DefaultApi.php(358): OpenAPI\Client\ObjectSerializer::buildQuery()
#1 /home/julian/workspace/tmp/openapi-enum-params/src/Api/DefaultApi.php(165): OpenAPI\Client\Api\DefaultApi->endpointRequest()
#2 /home/julian/workspace/tmp/openapi-enum-params/src/Api/DefaultApi.php(145): OpenAPI\Client\Api\DefaultApi->endpointWithHttpInfo()
#3 /home/julian/workspace/tmp/openapi-enum-params/test.php(10): OpenAPI\Client\Api\DefaultApi->endpoint()
#4 {main}
  thrown in /home/julian/workspace/tmp/openapi-enum-params/src/ObjectSerializer.php on line 583
openapi-generator version

7.17.0

OpenAPI declaration file content or url
openapi: 3.1.0
paths:
  /endpoint:
    get:
      operationId: endpoint
      parameters:
        - in: query
          name: array
          schema:
            type: array
            items:
              $ref: '#/components/schemas/Enum'
      responses:
        '200':
          description: Successful response

info:
  title: "Enum Example"
  version: 1.0.0
components:
  schemas:
    Enum:
        type: string
        enum:
            - A
            - B
Generation Details

openapi-generator-cli generate -g php-nextgen -i openapi.yaml
composer install

Steps to reproduce

Run the above commands and create a file like the following:

<?php

use OpenAPI\Client\Api\DefaultApi;
use OpenAPI\Client\Model\Enum;

require __DIR__ . '/vendor/autoload.php';

$client = new DefaultApi();

$client->endpoint([Enum::A]);

Run the file and see the error.

Related issues/PRs

I haven't found any.

Suggest a fix

In ObjectSerializer::toQueryValue the following code should be added to the else of the flattenArray function:

if ($v instanceof BackedEnum) {
    $v = $v->value;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions