OpenAPITools / OpenAPITools/openapi-generator

[BUG][java-vertx-web] Textual responses get wrapped in JSON

Open
#19,029 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Textual responses get wrapped in JSON, the current template calls .json regardless of output type.

if (apiResponse.hasData()) {
    routingContext.json(apiResponse.getData());
}
openapi-generator version

7.2.0
Also checked on latest master via Docker

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Example
  version: 1.0.0
paths:
  /example:
    post:
      operationId: postExample
      responses:
        200:
          description: Successful operation
          content:
            text/plain:
              schema:
                type: string
Generation Details
openapi-generator generate \
  -i ./api.yaml \
  "-g" "java-vertx-web"
Steps to reproduce

Run the above command

Related issues/PRs
Suggest a fix

Not the cleanest, but apiHandler.mustache can be:

...
                    var data = apiResponse.getData();
                    if ((Object) data instanceof String s) {
                        routingContext.response().end(s);
                    } else {
                        routingContext.json(data);
                    }
...

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 with the java-vertx-web template's apiHandler.mustache and reproduce the issue using the supplied OpenAPI YAML and generation command. Verify that a text/plain string response is sent as text rather than wrapped in JSON, while the existing JSON response behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.