-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
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
- BGeneration 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;
}Reactions are currently unavailable