OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.42k stars 6.48k forks source link

[BUG] [JAVA]Import Mapping does not work when returing List #7960

Closed piotrkav closed 2 years ago

piotrkav commented 3 years ago
Description

There is a problem when generating interface using openapi-generator-maven-plugin. When I want to return list of already defined object, openapi-generator creates ResponseEntity<List> instead of ResponseEntity<List> It works for single object.

Expected:

    @ApiResponse(code = 200, message = "returns all notifications for page", response = io.piotrkav.dto.NotificationDetails.class, responseContainer = "List") })
public ResponseEntity<List<io.piotrkav.dto.NotificationDetails>> getNotifications(...)

Actual:

    @ApiResponse(code = 200, message = "returns all notifications for page", response = io.piotrkav.dto.NotificationDetails.class, responseContainer = "List") })
public ResponseEntity<List<Object>> getNotifications(...)
openapi-generator version

5.0.0-beta

OpenAPI declaration file content or url
paths:
  notifications:
    parameters:
      - name: page
        in: query
        description: Selfcare notification view page
        required: true
        schema:
          type: integer
          format: int32
      - name: size
        in: query
        description: Selfcare notification view size
        required: true
        schema:
          type: integer
          format: int32
      - name: from
        in: query
        description: from date ISOString
        required: true
        schema:
          type: string
      - name: to
        in: query
        description: to date ISOString
        required: true
        schema:
          type: string
    get:
      summary: Returns all notifications for page from given period
      operationId: getNotifications
      tags:
        - sc-notification
      responses:
        '200':
          description: returns all notifications for page
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Notification'
components:
  schemas:
    Notification:
      type: object
      description: external NotificationDetails object
Generation Details

Configuration

    <plugins>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>5.0.0-beta</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/doc/api.yml</inputSpec>
              <skipIfSpecIsUnchanged>false</skipIfSpecIsUnchanged>
              <output>${project.build.directory}/generated-sources/openapi</output>
              <generatorName>spring</generatorName>
              <library>spring-boot</library>
              <apiPackage>com.comarch.telco.t3arts.api</apiPackage>
              <modelPackage>com.comarch.telco.t3arts.datamodel</modelPackage>
              <generateApis>true</generateApis>
              <generateApiDocumentation>true</generateApiDocumentation>
              <generateApiTests>false</generateApiTests>
              <generateModels>true</generateModels>
              <templateDirectory>${project.basedir}/gen_templates</templateDirectory>
              <generateModelDocumentation>true</generateModelDocumentation>
              <generateModelTests>false</generateModelTests>
              <generateSupportingFiles>false</generateSupportingFiles>
              <configOptions>
                <java8>true</java8>
                <dateLibrary>java8</dateLibrary>
                <useTags>true</useTags>
                <useBeanValidation>true</useBeanValidation>
                <configPackage>io.piotrkav.appconfig</configPackage>
                <interfaceOnly>true</interfaceOnly>
                <delegatePattern>false</delegatePattern>
                <skipDefaultInterface>true</skipDefaultInterface>
              </configOptions>
              <importMappings>
                 <importMapping>Notification=io.piotrkav.dto.NotificationDetails</importMapping>
              </importMappings>
            </configuration>
          </execution>
        </executions>
      </plugin>
Steps to reproduce

I use mvn command to generate the interfaces:

mvn clean compile
piotrkav commented 3 years ago

anyone? 🆘

sh4nks commented 2 years ago

I am having the same problem (funny side note: also with a Notification object :D)

@piotrkav did you find a solution/workaround to your problem?

wing328 commented 2 years ago

There's an option schemaMapping in the latest stable release: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#schema-mapping

Please use it instead.

wing328 commented 2 years ago

If there's still an issue, please open a new issue instead.