Repository navigation
[JAVA] Array of Strings as requestBody of a POST request in OAS3 #7592
Copy link
Copy link
Closed
Description
Description
According to #6745 it is possible to define POST request having a List of String as request body parameter.
In the generated Java client, the argument is a String where a List<String> is expected.
Swagger-codegen version
3.0.0-rc0.
pom.xml configuration:
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.0-rc0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec><!-- ... --></inputSpec>
<language>java</language>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.0-rc0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Swagger declaration file content or url
openapi: 3.0.1
info:
title: A dummy title
version: 1.0.0
paths:
/my/endpoint:
post:
summary: Returns a list
operationId: getMyList
requestBody:
description: The list to retrieve as csv
content:
application/json:
schema:
type: array
items:
type: string
required: true
responses:
'200':
description: Ok
content:
application/json:
schema:
type: string
# components sections is necessary to avoid a NullPointer Exception during code generation
components:
schemas:
Dummy:
type: string
Command line used for generation
mvn compile
Related issues/PRs
Suggest a fix/enhancement
The method signature for my endpoint in DefaultApi is public String getMyList(String body). It should be public String getMyList(List<String> body).
The code generated in DefaultApiTest is:
@Test
public void getMyListTest() throws ApiException {
String body = null;
String response = api.getMyList(body);
// TODO: test validations
}
Here the same: body should be List<String>
Swagger 2.0
As comparison, I tested everything with Swagger 2.0:
swagger: "2.0"
info:
title: A dummy title
version: 1.0.0
paths:
/my/endpoint:
post:
description: Returns a list
operationId: getMyList
parameters:
- in: body
name: body
description: The list to retrieve as csv
required: true
schema:
type: array
items:
type: string
produces:
- application/json
responses:
'200':
description: Ok
schema: {
type: string
}
Inspired by this StackOverflow question: Specify an array of strings as body parameter in swagger API
With io.swagger:swagger-codegen-maven-plugin:2.3.1 the generated code works with a List, as expected.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
jmini commentedon Feb 15, 2018
I have proposed a Pull Request in the corresponding git repository: swagger-api/swagger-codegen-generators#13
jmini commentedon Feb 16, 2018
Verified with
io.swagger:swagger-codegen-generators:1.0.0-SNAPSHOT. It works for me.