swagger-api / swagger-api/swagger-codegen

When API response is a MAP, the generated API interface does not contain import java.util.Map;

Open
#6,893 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When API response is a MAP, the generated API interface does not contain import java.util.Map;

generated-api-interface

Swagger-codegen version

tested with 2.2.3, 2.3.0 and 3.0.0

Swagger declaration file content or url
swagger: '2.0'

info:
  version: 0.0.0
  title: Following yaml generates an interface that has a missing import

paths:
  /testingMapResponse:
    get:
      produces:
        - application/json
      parameters:
        - name: clientID
          in: query
          required: true
          type: string
          minLength: 2
          maxLength: 4
      responses:
        200:
          description: Response is a map
          schema:
            title: Testing
            type: object
            description: This should be a map (<String, List<String>).
            additionalProperties:
              type: array
              items:
                type: string
                minLength: 3
                maxLength: 25
        400:
          description: Invalid Request Submitted
          schema:
            $ref: '#/definitions/APIErrors'
        404:
          description: Not found
          schema:
            $ref: '#/definitions/APIErrors'


definitions:
  APIErrors:
    description: a list of errors
    type: array
    items:
      $ref: '#/definitions/APIError'

  APIError:
    description: Error information
    type: object
    properties:
      message:
        description: a text description describing the error
        type: string

Related issues/PRs

This issue seems to be similar to https://github.com/swagger-api/swagger-codegen/issues/2937

Suggest a fix/enhancement

I can submit a PR if you point me on the right direction?

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 generated Java API interface with the Swagger 2.0 YAML in the issue, focusing on the response schema using additionalProperties. Trace how the generator determines imports for that response type; done means the generated interface includes java.util.Map and compiles across the reported versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, 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.