Skip to content

[BUG] [JAVA] [SPRING] missing import for schemaMapping in api #24232

Description

@jpfinne

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

schemaMapping + importMapping does not generate the import in the generated apis class.

It works only for Models.
typeMapping + importMapping correctly generated the parameters and the imports.

Example:

openapi-generator version

7.23.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: "1.0.0"
  title: mapping
paths:
  /some/dummy/endpoint/{id}:
    get:
      operationId: getDummy
      parameters:
        - name: id
          in: path
          required: true
          description: My Custom Id
          schema:
            $ref: '#/components/schemas/MyId'
        - name: key
          in: query
          required: true
          description: filter on key
          schema:
            $ref: '#/components/schemas/MyKey'

      responses:
        200:
          description: Successfully created reverse listings for retail
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Dummy'
components:
  schemas:
    Dummy:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/MyId'
        key:
          $ref: '#/components/schemas/MyKey'
    MyId:
      type: string
      format: custom
    MyKey:
      type: string
Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g spring -i mapping.yaml -o /tmp/spring/ --type-mappings string+custom=MyCustomId --schema-mappings MyKey=MyCustomKey --import-mappings MyCustomId=org.myord.MyCustomId --import-mappings MyCustomKey=org.myorg.MyCustomKey

Steps to reproduce

The generated SomeApoi.java has the correct method:

ResponseEntity<Dummy> getDummy(MyCustomId id,     MyCustomKey key)

and the correct import for MyId
import org.myord.MyCustomId;

But no import for MyKey (or MyCustomKey)

The models contain the correct imports. Dummy.java contains

import org.myord.MyCustomId;
import org.myorg.MyCustomKey;
Related issues/PRs
Suggest a fix

Workaround: use fully qualified name in schema-mappings

--schema-mappings MyKey=org.myorg.MyCustomKey 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions