swagger-api / swagger-api/swagger-codegen

[Java] No Import Statement generated for Nested additionalProperties field

Open
#9,574 3 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

I have a return type for a 200 response code that is a nested "additionalProperties" field that generates to Map<String, Map<String, Link>>. Within the generated SDK code, the generator omits the import for the Link class. It omits it for both the API class (WebMvcLinksHandlerApi.java) as well as the associated test class (WebMvcLinksHandlerApiTest.java). As a result, the Java code does not compile without manually adding the import.

Swagger-codegen version

3.0.10

I have also tried other version and it failed in those too.

Swagger declaration file content or url

Nested additional Properties

"additionalProperties":{
   "type":"object",
   "additionalProperties":{
      "$ref":"#/definitions/Link"
   }
}

Nested additional Properties with more JSON context

"/actuator":{
      "get":{
        "tags":[
          "web-mvc-links-handler"
        ],
        "summary":"links",
        "operationId":"linksUsingGET",
        "produces":[
          "application/json",
          "application/vnd.spring-boot.actuator.v2+json"
        ],
        "parameters":[
          {
            "name":"x-vol-site",
            "in":"header",
            "required":false,
            "type":"integer",
            "format":"int32"
          },
          {
            "name":"x-vol-tenant",
            "in":"header",
            "required":true,
            "type":"integer",
            "format":"int32"
          }
        ],
        "responses":{
          "200":{
            "description":"OK",
            "schema":{
              "type":"object",
              "additionalProperties":{
                "type":"object",
                "additionalProperties":{
                  "$ref":"#/definitions/Link"
                }
              }
            }
          },
          "401":{
            "description":"Unauthorized"
          },
          "403":{
            "description":"Forbidden"
          },
          "404":{
            "description":"Not Found"
          }
        },
        "deprecated":false
      }
    }
Command line used for generation

swagger-codegen generate -i swagger.json -l java -c config.json -o tmp/

Steps to reproduce

Generate and compile via mvn clean install

Related issues/PRs

Maybe https://github.com/swagger-api/swagger-codegen/issues/3140 ?

Suggest a fix/enhancement

N/A

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 provided nested additionalProperties schema and the swagger-codegen generate command, then run mvn clean install. Inspect generation of WebMvcLinksHandlerApi.java and WebMvcLinksHandlerApiTest.java; done means both compile with the required Link import generated automatically.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.