Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scala] Collection parameters not serializing properly #7174

Open
bchess opened this issue Dec 13, 2017 · 1 comment
Open

[Scala] Collection parameters not serializing properly #7174

bchess opened this issue Dec 13, 2017 · 1 comment

Comments

@bchess
Copy link

bchess commented Dec 13, 2017

Description

Collection parameters get serialized via toString(), resulting in URL parameters like List%28123%29 for List(123).

Swagger-codegen version

2.3.0

Swagger declaration file content or url
{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Collection parameter issue",
    "description": "An endpoint that takes a collection as a parameter",
    "termsOfService": "http://swagger.io/terms/"
  },
  "host": "example.com",
  "basePath": "/api",
  "schemes": [
    "http"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/hi": {
      "get": {
        "operationId": "hi",
        "parameters": [
          {
            "collectionFormat": "csv",
            "description": "Comma separated list of integers",
            "in": "query",
            "items": {
              "type": "integer"
            },
            "name": "numbers",
            "required": true,
            "type": "array"
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        },
        "tags": [
          "hi"
        ]
      }
    }
  }
}
Command line used for generation

java -jar swagger-codegen.jar generate --lang scala -i collection-issue.json

Steps to reproduce
val api = new HiApi(defBasePath="http://localhost:8080")
val result = api.hi(List(1, 2, 3))

Start a simple webserver on 8080 python -m SimpleHTTPServer 8080

Observe:


127.0.0.1 - - [13/Dec/2017 15:29:19] "GET /hi?numbers=List%281%2C%202%2C%203%29 HTTP/1.1" 404 -

Related issues/PRs

#6540 implemented support for collections, but I don't think it ever worked properly, at least for parameters. Notably, adding an escape() function for List[String] is useless when invokeApi's queryParams is Map[String, String].

Suggest a fix/enhancement

Serialization should be addressed inside api.mustache, replacing/augmenting param.toString call with a call to escape() instead. Also see java's parameterToString() as another valid approach.

@bchess bchess changed the title [SCALA] Collection parameters not serializing properly [Scala] Collection parameters not serializing properly Dec 13, 2017
@wing328
Copy link
Contributor

wing328 commented Jan 29, 2018

@bchess I would suggest you also try the akka-scala client as well since the focus will be on the akka-scala client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants