swagger-api / swagger-api/swagger-codegen

[python] swagger responses versus API behavior

Open
#1,796 6 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Enhancement: Feature
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

my swagger.json has:

"responses" : {
    "200" : {},
    "400": {}
}

but the python API ( https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/python/rest.mustache#L176 ) has:

        if r.status not in range(200, 206):
            raise ApiException(http_resp=r)

which means that when a web service returns a 400, the machinery in the generated client code that converts the JSON response in the body into the swagger-generated response object never happens.

Now maybe the idea is that the caller is supposed to catch ApiException and examine self.status for a 400 error, but then how is the http response body supposed to be converted into the schema specified in the "400" section of the swagger file?

I have also looked at the Java client ( https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java#L525 ) and it also doesn't do the right thing with any http-reponse-code outside of a 2xx

some clarification one how exactly the non-200 responses should be handled would be useful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue points to modules/swagger-codegen/src/main/resources/python/rest.mustache#L176 and samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java#L525; start by comparing their non-2xx response handling with the declared Swagger responses. Done means the expected treatment of a documented 400 response, including its body and schema conversion, is established and reflected consistently or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.