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.56k stars 6.52k forks source link

[BUG][JAVA][spring] array/list missing in generated @ApiResponse and example #13332

Open b-schmitzer opened 2 years ago

b-schmitzer commented 2 years ago

Bug Report Checklist

Description

Generated method with response/return of type array is missing the array and instead only using the wrapped object. The following locations are affected:

@ApiResponse

expected:

@ApiResponse(responseCode = "200", description = "Get an array/list of objects", content = {
    @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = ReturnArrayGet200ResponseInner.class)))
})

actual:

@ApiResponse(responseCode = "200", description = "Get an array/list of objects", content = {
    @Content(mediaType = "application/json", schema = @Schema(implementation = ReturnArrayGet200ResponseInner.class))
})
exampleString

expected:

String exampleString = "[{ \"property2\" : \"property2\", \"property1\" : 0 }]";

actual:

String exampleString = "{ \"property2\" : \"property2\", \"property1\" : 0 }";
additional notes
openapi-generator version

v6.0.1

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Demo
  description: Demo for Bugreport
  version: 1.0.0

paths:
  /return-array:
    get:
      responses:
        '200':
          description: 'Get an array/list of objects'
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    property1:
                      type: integer
                      format: int64
                    property2:
                      type: string
                      maxLength: 255
Generation Details

Generated via openapi-generator-maven-plugin:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.0.1</version>
    <executions>
        <execution>
            <id>generate-test</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/api/test.yml</inputSpec>
                <generatorName>spring</generatorName>
                <library>spring-boot</library>
                <output>${project.build.directory}/generated-sources/openapi/test</output>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce
  1. create a new maven project
  2. place the provided test.yml into its api directory
  3. add the provided plugin configuration to your pom.xml
  4. generate the API, e.g.: mvn clean package
  5. check the generated ReturnArrayApi.java
Suggest a fix

The Mustache files responsible for the marked locations might ignore the array type or detect it incorrectly.

sdewinter-maqqie commented 1 year ago

Seems like it's due to the hardcoded content schema definition in api.mustache. Seems like the same goes for the kotlin-spring module in apiInterface.mustache.