swagger-api / swagger-api/swagger-codegen

SpringCodegen not importing java.util.Map

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

When using the codegen maven plugin and the Spring language, java.util.Map is not being imported when the Map's value is a List.

Swagger-codegen version

Maven plugin version 2.3.1

Swagger declaration file content or url
paths:
  /customer:
    get:
      tags:
        - Customers
      summary: Retrieve all customers
      produces:
        - application/json
      responses:
        '200':
          description: OK
          schema:
            type: object
            additionalProperties:
              type: array
              items:
                type: string

the output of this is correct

default ResponseEntity<Map<String, List<String>>>

but the class does not have java.util.Map imported, and therefore fails to build

target/generated-sources/swagger/src/gen/java/main/io/swagger/api/CustomerApi.java:[54,28] cannot find symbol
  symbol:   class Map
  location: interface io.swagger.api.CustomerApi

Maven configuration
<plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.3.1</version>
                <executions>
                    <execution>
                        <id>generate-server</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>swagger.yaml</inputSpec>
                            <language>spring</language>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <delegatePattern>true</delegatePattern>
                                <java8>true</java8>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

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 swagger-codegen Maven plugin, the Spring language, and the YAML schema shown; inspect the generated CustomerApi.java output and the SpringCodegen import-generation path. Done means the generated response still uses Map<String, List> and CustomerApi.java includes the required java.util.Map import so the project builds.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.