swagger-api / swagger-api/swagger-codegen

Invalid java client code is generated when body parameter is a map.

Open
#7,565 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

When body parameter is a map, generated code is not correct.
Currently "Object" is generated. It should have been Map<String, Object>

Swagger-codegen version 2.2.3
Swagger declaration file content or url
{
            "in": "body",
            "name": "body",
            "description": "description",
            "required": true,
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "object"
              }
            }
          }
Command line used for generation

generate -i swagger.json -l java -o output

Suggest a fix/enhancement

Generated Code:

 public ApiResponse<RefLinkDto> methodName( Object body) throws ApiException {
   
    }

Correct Code: 

 public ApiResponse<RefLinkDto> methodName(Map<String, Object> body) throws ApiException {
   
    }


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 by reproducing the issue with the generate command, the supplied Swagger body-parameter schema, and the Java target. Trace how Java client method parameters are selected for object schemas with additionalProperties; done means the generated method uses Map<String, Object> instead of Object for this input.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.