Skip to content

[Java][Spring] Adds missing import for Map - Fixes #7432 #7510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aykutakin
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger

Description of the PR

Java Spring code generator has missing java.util.Map import when api return type is Map.

Tested with:

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

Fixes #7432

@wing328
Copy link
Contributor

wing328 commented Jan 28, 2018

@aykutakin thanks for the PR. Would this result in duplicated import of "java.util.Map" if there are more than 1 response with the type Map?

@aykutakin
Copy link
Contributor Author

I thought I've tested it, but apparently tested it wrong. Thanks for pointing that out again @wing328. When I change the input yaml as in below, as you've foreseen, it generates 2 java.util.Map imports:

paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          type: integer
          format: int32
      responses:
        "200":
          description: A paged array of pets
          headers:
            x-next:
              type: string
              description: A link to the next page of responses
          schema:
            type: object
            additionalProperties:
              type: array
              items:
                type: string
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/Error'
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          type: string
      responses:
        "200":
          description: Expected response to a valid request
          schema:
            type: object
            additionalProperties:
              type: array
              items:
                type: string
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/Error'

Template file also has hard coded java.util.List import. Which results with also unnecessary multi import of java.util.List, since another import also comes from {{#imports}} section in this case. I think cleaning up is a different issue and for now doesn't cause catastrophic results. Importing java.util.Map like List is one way of resolving this issue, but I'll look for a better way to handle this before jumping to easiest solution.

@aykutakin
Copy link
Contributor Author

Change has been made to import complex type's through {{import}} tag. There is already additional complex type check for Parameters. With this change, it has been also added to Response.

Copy link

@jeff9finger jeff9finger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants