swagger-api / swagger-api/swagger-codegen
[qt5cpp] Different response objects depending on http status code
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
According to the yaml specification (in our case swagger 2.0) a response can return different types (or objects) depending on the returned HTTP status code. However when generating client code (in our case qt5cpp), it doesn't generate different callback signals depending on the HTTP status code. It only generates code to return an object in case of success.
Swagger-codegen version
We are using swagger 2.4.0 (snapshot 20180725)
Swagger declaration file content or url
Sample of yaml definition for POST of a Pet (based on Pets example):
paths:
/pet:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
201:
description: "Created OK"
schema:
$ref: "#/definitions/Pet"
405:
description: "Invalid input"
schema:
$ref: "#/definitions/ErrorResponse"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
Command line used for generation
java -jar swagger-codegen-cli-2.4.0-20180725.142346.303.jar generate -i ./swagger.json -c config.json -o . -lqt5cpp
Steps to reproduce
For e.g. a post method, define different schema's for different HTTP codes.
Generate code.
Only a callback slot for HTTP code 201 (object type Pet) is created, but not for code 405 (object type ErrorResponse).
Related issues/PRs
So far, I have found two issues that report a similar problem for other languages:
- php: #8159
- python: #5186
Not sure if this can be fixed in common code or only in language specific code.
Suggest a fix/enhancement
In the generated Post callback method the response is always translated into a SWGPet object (in case of no errors). This is correct.
In case of an error, a check has to be done on HTTP status codes. to generate a signal passing a SWGErrorResponse.
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
Start by generating a qt5cpp client from the provided Pet POST definition with the stated swagger-codegen command, then inspect the generated Post callback method and the qt5cpp templates that produce it. Compare the existing 201 Pet handling with the missing 405 ErrorResponse handling; done means distinct response callbacks or signals are generated for both status-code schemas.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100