swagger-api / swagger-api/swagger-codegen

[Python] - swagger flask / connexion- server - Error handling documentation

Open
#7,077 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I am having a hard time working in the error handling for the swagger server stub.
First of all, I was creating a server stub.

I have a pet, in my API lets say. I want to have pets with a unique name.
In the POST /pet I will pass "name" parameter so I will check on the controller if this already exists, return an error.
I have an ExceptionDetail on my models, which purpose is to handler different errors.
ExceptionDetail model contains the tittle(str), status(int), detail(str), etc.

Also, swagger validates the fields provide depending if they are required or not.
I was checking https://swagger.io/docs/specification/describing-responses/
the documentation of swagger but it is a minimal example in which they describe the code 200 not even default is there.

I went back and checked the petstore example https://github.com/swagger-api/swagger-codegen/blob/master/samples/server/petstore/flaskConnexion/swagger_server/swagger/swagger.yaml

  1. I noticed that there is an APIResponse definition: 1) do I need one on my project in order to handler errors? like 409 or any 3xx 4xx ?
  2. Currently I am returning the object generated, in this case a Pet instance. Does that means that I need to create an APIResponse insert he pet instance and return it when a 200 http code?
  3. I was reading about this topic on other sites. I end up reading this one https://github.com/swagger-api/swagger-codegen/issues/922
    It suggest using abort, and this one about the abort: http://flask-restplus.readthedocs.io/en/stable/errors.html
    Right now, I do not know if that applies, but I was giving it a try.

First I was generating an instance of the ExceptionDetail with the data i needed. I was returning the exception instance ##Result: The server response code is 200.
Then, I was using the flask abort, and it keeps returning 200.

Finally, I saw on the petstore yalm that there are some response error described like in the PUT /pet
So i went to the controller and found it is not implemented, it is just the stub.

I just want to generated the proper response.code = 3xx or 4xx and include my Exception instance describing the issue. So the server is not going to reply with a 200 all the time.

Swagger-codegen version

2.0

Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

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

Start with the referenced petstore swagger.yaml and the generated Flask/Connexion controller, then compare documented error responses with the current stub behavior. Clarify how non-200 responses and the ExceptionDetail model should be represented, and document or implement a resolved approach with a reproducible example.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.