OpenAPITools / OpenAPITools/openapi-generator
[BUG] all languages: not handling array parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I'm using the swift4 generator, with a Swagger 2 spec, and an array parameter with collectionFormat=csv. The parameter looks like:
{
"name": "categories",
"in": "path",
"required": true,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv"
}
It generates code that (correctly) expects an array of strings:
open class func usersGet(categories: [String], completion: @escaping ((_ data: [User]?,_ error: Error?) -> Void)) {
But if I pass an array to it:
DefaultAPI.usersGet(categories: ["sample"] )
it URL-encodes the array literal, rather than using comma-separated values as specified in collectionFormat:
GET /users/%5B%22sample%22%5D
I'm curious if this will be an issue with all generator types.
openapi-generator version
4.0.0-SNAPSHOT
OpenAPI declaration file content or url
https://gist.github.com/jacobweber/2a8b3145952464997545d212772a1b96
Command line used for generation
java -jar /path/to/openapi-generator-cli.jar generate -i /path/to/spec.json -g swift4 -o /path/to/output
Steps to reproduce
See above
Related issues/PRs
None
Suggest a fix
This is not Swift, but swagger-codegen had a fix for one Java client here, and a PR for another one here.
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 supplied Swagger 2 declaration and the generated Swift4 client from the documented generation command. Reproduce the path request using the categories array and compare its URL encoding with the declared collectionFormat=csv behavior. Done means the generated request uses comma-separated array values rather than encoding the array literal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100