Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2292
Closed
Open
Issue created Mar 04, 2019 by Administrator@rootContributor

[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

ampersand_query_param

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;
Assignee
Assign to
Time tracking