swagger-api / swagger-api/swagger-codegen

[Java] Fix for issue 3638 must be ported to jersey2

Open
#9,482 0 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

Description

For a query parameter of type "array" and collectionFormat "csv", the Java jersey2 generated API percent-encodes the commas that separate the individual values. This is incorrect behaviour, as the commas are used as delimiters, not data, and should not be encoded.

For example, the following:

/test?param=a,b,c

becomes:

/test?param=a%2Cb%2Cc
Swagger-codegen version

master

Swagger declaration file content or url
{
  "swagger": "2.0",
  "info": {
    "title": "test spec",
    "version": "1.0"
  },
  "parameters": {
    "testParam": {
      "name": "test",
      "in": "query",
      "type": "array",
      "items": {
        "type": "string"
      },
      "collectionFormat": "csv"
    }
  },
  "paths": {
    "/test": {
      "get": {
        "description": "test get",
        "parameters": [
          {
            "$ref": "#/parameters/testParam"
          }
        ],
        "references": {

        }
      }
    }
  }
}
Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -Dlibrary=jersey2 -i test.json -l java -o test-java

Steps to reproduce
  1. Generate and build the Java API for the above specification.
  2. Create a new DefaultApi instance.
  3. Call the testGet function with several strings a List passed to the test parameter.
  4. The API will send an HTTP request with a URI looking like the following:
/test?test=string1%2Cstring2%2Cstring3

This should instead be

/test?test=string1,string2,string3
Related issues/PRs

Issue #3638, PR #4908.

Suggest a fix/enhancement

I will be submitting a PR shortly with a fix.

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

Review issue #3638 and PR #4908 first, then generate the jersey2 Java client with the command shown and exercise a List of strings for the test query parameter. Done means the generated request uses literal commas between CSV values rather than percent-encoding them.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
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.