swagger-api / swagger-api/swagger-codegen
API does not have a return value. but API spec has
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Generated API does not return the HTTP response code.
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?
swagger-codegen-3.0.0
Swagger declaration file content or url
49 /switches:
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
Command line used for generation
java -jar swagger-codegen-cli-3.0.0-20180710.190537-87.jar generate -i teamApiSpec.yaml -l java --additional-properties jackson=true --artifact-id swagger-java-client-api
Generated Java code:
/**
* 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);
}
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 generation using teamApiSpec.yaml, swagger-codegen-3.0.0, the Java language option, and the shown command. Then trace the Java generator templates or response-handling entry point to understand why the declared 200 and 400 responses produce ApiResponse; done means the generated API exposes the response information described by the specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100