swagger-api / swagger-api/swagger-codegen

[PHP] Generated APIs incorrectly encode commas in certain query parameters

Open
#10,046 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I have the same json definition but by different swagger-codegen have the deffirent in source code of API:

Version 2.4.8:

        if (is_array($filter_number)) {
            $filter_number = ObjectSerializer::serializeCollection($filter_number, 'csv', true);
        }
        if ($filter_item_number !== null) {
            $queryParams['filter[number]'] = ObjectSerializer::toQueryValue($filter_number);
        }

Version 2.4.9 and more:

        if (is_array($filter_number)) {
            $queryParams['filter[number]'] = $filter_number;
        }
        if ($filter_item_number !== null) {
            $queryParams['filter[number]'] = ObjectSerializer::toQueryValue($filter_number);
        }

Swagger Parameter: "collectionFormat: csv"

Description

The problem exist only for query params but it work correct for header params. (same functionality by version 2.4.8 and starting at 2.4.9)

Swagger-codegen version

starting at 2.4.9

Swagger declaration file content or url
...
        - name: 'filter[number]'
          in: query
          required: false
          items:
            type: string
          type: array
          collectionFormat: csv
          uniqueItems: true
...
Command line used for generation

unknown. It used from https://app.swaggerhub.com/
I can reproduce with: java -jar swagger-codegen-cli-2.4.12.jar generate -i the.json -l php -o /tmp/test

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PHP generator output produced by swagger-codegen-cli-2.4.12.jar and inspect the query-parameter handling around ObjectSerializer::serializeCollection and ObjectSerializer::toQueryValue. Reproduce the issue using the supplied YAML shape and generation command, then compare query and header parameters. Done means CSV query values preserve the expected comma encoding behavior without regressing header parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.