Skip to content

[BUG] all languages: not handling array parameters #2125

Open
@jacobweber

Description

@jacobweber

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions