swagger-api / swagger-api/swagger-codegen
[PHP] Generated APIs incorrectly encode commas in certain query parameters
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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