I am using swagger-codegen-3.0.0.
As shown below, the API specification has responses 200 and 400; however, when the addTeam() API is generated, it is generated with the return type 'void'.
I want to handle the response code 200 and/or 400. Does it mean I have explicitly, define the payload type in the response specification? Can someone please provide more details on how my 'responses' specification should be?
49 /team:
50 post:
51 summary: Add team
52 operationId: addTeam
53 requestBody:
54 description: Team detail being added
55 content:
56 application/json:
57 schema:
58 type: array
59 items:
60 $ref: "#/components/schemas/addTeamPayload"
61 responses:
62 200:
63 description: Ok
64 400:
65 description: Bad request
66 tags:
67 - Team
java -jar swagger-codegen-cli-3.0.0.jar generate -i teamApiSpec.yaml -l java --additional-properties jackson=true --artifact-id swagger-java-client-api
This command generates the below Java code/APIs.
/**
* Add team
*
* @param body Team detail being added (optional)
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public void addTeam(List<AddTeamPayload> body) throws ApiException {
addTeamWithHttpInfo(body);
}
/**
* Add Team
*
* @param body Team detail being added (optional)
* @return ApiResponse<Void>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<Void> addTeamWithHttpInfo(List<AddTeamPayload> body) throws ApiException {
com.squareup.okhttp.Call call = addTeamValidateBeforeCall(body, null, null);
return apiClient.execute(call);
}
Another issue is even though 400 response code is programmed in the API spec, when server returns 400, the API still throws an exception and in process, the return code details are lost. As a user of the API, I do not know what return code is returned or what return response message is sent by the server.
Can someone please comment on this? This is important. Let me know if I have missed something in my API spec.