OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][spring] array/list missing in generated @ApiResponse and example
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
- the actual return type is correctly wrapped in a List:
List<ReturnArrayGet200ResponseInner> - generation via https://editor.swagger.io/ doesn't have the problem
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
- create a new maven project
- place the provided
test.ymlinto itsapidirectory - add the provided plugin configuration to your
pom.xml - generate the API, e.g.:
mvn clean package - 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided test.yml and openapi-generator-maven-plugin configuration, then inspect the generated ReturnArrayApi.java and the responsible Mustache files. Done means the generated @ApiResponse and exampleString preserve the array shape while the return type remains List.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100