swagger-api / swagger-api/swagger-codegen

[JAVA][library: vertx] generated client fails to deserialize text/plain endpoints

Open
#9,614 0 comments 1 reaction 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:

Java-vertx client fails to deserialize text/plain endpoints due attempt to deserialize non-Json content:

Json.decodeValue(httpResponse.body(), returnType);
Swagger-codegen version:

2.4.7.

Swagger declaration file content or url
/metrics:
    get:
      tags:
      - "metrics"
      operationId: "getMetrics"
      produces:
      - text/plain
      responses:
        200:
          description: "Metrics"
          schema:
            type: "string"
Command line used for generation
java -DsupportingFiles -Dmodels -DmodelDocs=false -DmodelTests=false -Dapis -jar ./swagger-codegen-cli-2.4.7.jar \
generate -i swagger-api.yaml --lang java --additional-properties basePackage=service \
--api-package api --model-package model --additional-properties configPackage=configuration \
--additional-properties java8=true --additional-properties dateLibrary=java8 \
--additional-properties sourceFolder=generated-sources --additional-properties library=vertx -o src/main;
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

add another type check into if-else sieve (ApiClient.buildResponseHandler), e.g.:

if ("byte[]".equals(returnType.getType().toString())) {
    resultContent = (T) httpResponse.body().getBytes();
} else if (AsyncFile.class.equals(returnType.getType())) {
    handleFileDownload(httpResponse, handler);
    return;
} else {
    if ("java.lang.String".equals(returnType.getType().getTypeName())) {
        resultContent = (T) new String(httpResponse.body().getBytes());
    } else {
        resultContent = Json.decodeValue(httpResponse.body(), returnType);
    }
}

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

Start at the generated Java-Vert.x client entry point named ApiClient.buildResponseHandler and compare handling for text/plain with the provided /metrics response schema. Reproduce generation with the supplied swagger-codegen command, then verify that a String response is handled without passing non-JSON content to Json.decodeValue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.