-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JAVA][SPRING] Arrays are not rendered correctly in responses #14178
Comments
For me, in the generated API class the return type is set to openapi: 3.1.0
info:
title: Cats API
version: 0.1.0
summary: API for Cats
description: Practice project for OpenAPI specification
paths:
/cats:
post:
description: Add a new cat
summary: Add a cat
operationId: addCat
requestBody:
description: Request for creating a new cat
content:
'application/json':
schema:
$ref: '#/components/schemas/Cat'
responses:
'201':
description: Cat has been added successfully.
get:
description: Get all cats
summary: Get Cats
operationId: getCats
responses:
'200':
description: Cats response
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/Cat'
components:
schemas:
Cat:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string
description:
type: string
status:
type: string
enum:
- available
- adopted
- dead
CatsAPI.java /**
* GET /cats : Get Cats
* Get all cats
*
* @return Cats response (status code 200)
*/
@Operation(
operationId = "getCats",
summary = "Get Cats",
responses = {
@ApiResponse(responseCode = "200", description = "Cats response", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Object.class))
})
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/cats",
produces = { "application/json" }
)
default ResponseEntity<Object> getCats(
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} POM.xml <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.2.1</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin> |
My team is facing the same issue. |
When using
in the response method (DefaultApi.java), which is now a double bug. First you need:
to avoid an empty response. Secondly, the final result should be
with regards to the array nature of the response object. Just confirming that theses are two separate problems, as described in #14200. Thanks @borsch! |
@superplan please try latest 6.3.0-SNAPSHOT |
Using 6.3.0-SNAPSHOT (Build from Fri Jan 13 14:03:03 UTC 2023) it works with openapi versions |
@superplan 3.1.0 is not unsupported as for now so it's a kind of expected result |
That's fine with me. The issue can be closed now, since it will be resolved with generator version |
Has version
Update:
That field is an array with This is in the Saw that the |
The issue above is fixed by #14496 (6.3.0 release). |
In version 6.6.0 the method |
Description
Objects of type "array" are not rendered correctly in responses, see example below. The UI shows only an item of the array, which is misleading.
openapi-generator version
6.2.1
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli-6.2.1.jar generate -g spring -i input.yaml -o "spring_6.2.1" -c config.yaml
Here is my config.yaml:
Produces:
Expect:
Steps to reproduce
Generate spring-Server und run as java application. Schema for the response code 200 is "Donut" and not an array of "Donut".
Related issues/PRs
Suggest a fix/enhancement
Incorporate @ArraySchema into api.mustache. Here the fix is code enclosed by tag "{{#isArray}}":
Now the DefaultApi.java should look like this:
Instead of:
The text was updated successfully, but these errors were encountered: