Add Open API prefix route - correct docs behind reverse proxy by kabirkhan · Pull Request #26 · fastapi/fastapi

I run a lot of services in Kubernetes using Ambassador as my API Gateway. Ambassador allows you to configure a route prefix for each one of your services and then it handles ingress and routing to the initial service. This PR enables me to configure the same prefix I use with Ambassador in the Swagger UI API docs.

Example:

prefix='/service1'

app = FastAPI(
    openapi_prefix=prefix
)
@app.get('/something') => SwaggerRoute (GET - /service1/something)

NOTE: This is not the same as using the include_router method and adding a prefix.
This is meant only to rewrite the route paths in the Swagger UI.

BTW: Awesome Project! Thanks so much for your work on this, I'm using fastapi a ton these days.