[BUG][PHP] Serialize exploded query params array of type string-array of style form
Created by: githubERIK
Bug Report Checklist
Description
Given a get request with optional, exploded, form-style, schema-type-array query parameters of type string (see OpenAPI declaration and steps-to-reproduce below). When the generated php client code processes the array of query parameters. Then it does not create the same result of ampersand-connected query as http://editor.swagger.io/ shows
Actual ?someParamName=0%3DoneValue%261%3DotherValue%262%3DanotherValue
Expected ?someParamName=oneValue&someParamName=otherValue&someParamName=anotherValue
openapi-generator version
master branch (version 3.3.4)
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Example API
version: 0.0.1
servers:
- url: 'https://some.example.api.com/v1'
paths:
/notes:
get:
summary: Returns all notes.
operationId: fetchNotes
parameters:
- in: query
name: labelIds
required: false
schema:
type: array
items:
type: string
style: form
explode: true
responses:
'204':
description: An object containing a list of group objects.
from example repo.
Eventually expect this ?labelIds=LabelOne&labelIds=LabelTwo&labelIds=LabelThree
but the result is ?labelIds=0%3DLabelOne%261%3DLabelTwo%262%3DLabelThree
.
Command line used for generation
openapi-generator generate -g php
Steps to reproduce
From https://github.com/githubERIK/openapi-php-multiparam-bug-example/commits/master
- Generate PHP client based on example.yaml
- Set name in composer.json
- Print failed query
... which is done in https://github.com/githubERIK/openapi-php-multiparam-bug-example.
After that clone try it out like in https://github.com/githubERIK/openapi-php-multiparam-bug-tryout with steps described in the README.
Related issues/PRs
Similar, but different: https://github.com/OpenAPITools/openapi-generator/issues/1763.
Suggest a fix
Workaround: in the generated file under the comment // query params
: lib/Api/DefaultApi.php#L234 replace
this
if (is_array($label_ids)) {
$label_ids = ObjectSerializer::serializeCollection($label_ids, 'multi', true);
}
if ($label_ids !== null) {
$queryParams['labelIds'] = ObjectSerializer::toQueryValue($label_ids);
}
by this
$queryParams['labelIds'] = $label_ids;