Skip to content

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

@bsch92

Description

@bsch92

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions