You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
}
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 aList<String>
is expected.Swagger-codegen version
3.0.0-rc0
.pom.xml configuration:
Swagger declaration file content or url
Command line used for generation
Related issues/PRs
#6745
Suggest a fix/enhancement
The method signature for my endpoint in
DefaultApi
ispublic String getMyList(String body)
. It should bepublic String getMyList(List<String> body)
.The code generated in
DefaultApiTest
is:Here the same:
body
should beList<String>
Swagger 2.0
As comparison, I tested everything with Swagger 2.0:
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.The text was updated successfully, but these errors were encountered: