vapor-ware / fastapi-rfc7807

RFC-7807 compliant problem detail error response handler for FastAPI applications
GNU General Public License v3.0
19 stars 7 forks source link

add ability to register Problem schema with OpenAPI #11

Closed edaniszewski closed 4 years ago

edaniszewski commented 4 years ago

This is useful because you may want to specify the response info using the actual content header, e.g. application/problem+json. If you pass the Problem schema to a route's responses as a model, it seems to just use its return type as application/json. Still technically correct, but it could be nice to know the full thing.

Specifying the response would at this point still be left to the user

@app.get(
  path='/',
  responses={
    401: {
        'description': 'something bad',
        'content': {'application/problem+json': {
            'schema': {
                '$ref': '#/components/schemas/Problem',
            },
        }},
    }
  },
)

in the future we could maybe include a util to include some of this boilerplate as well, but that seems out of scope for this issue.

there should be a flag for this in the register method which could be either a string, or bool, defaulting to False.

If True, it will augment the OpenAPI scheme with the Problem schema under the "Problem" name. If a string, it will register it under that string as the name.

If false, it will not register.