Skip to content

base href for swagger spec and ui #544

@eterna2

Description

@eterna2

Is your feature request related to a problem? Please describe.
Our fastapi service is place behind a proxy using path-based routing - i.e. /docs becames /foo/docs

This result in the default swagger spec as well as the swagger UI to fails as the openapi path passed to the html is an absolute ref (i.e. /docs or /prefix/docs) which will resolve incorrectly if there is a non-fastapi path routing.

See https://github.com/tiangolo/fastapi/blob/fc7d123347591c0d79505ee0c6a3a5ace70192f1/fastapi/applications.py#L91

Describe the solution you'd like
Either incorporate a base href argument to fast API, or set the openapi_url to relative ref (i.e. ./docs or ./prefix/docs).

Similar fix should be done for the openapi spec generation.

I would prefer the former solution as it will also correctly generate the openapi spec (to include the non-fastapi prefix).

Describe alternatives you've considered
Currently I provision my own custom route with the modified swagger UI HTML as well as the openapi spec.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions