Issue 1:
Describe the bug

The problem is basically the one described here:

#51 (comment)

My fastapi app is behind a reverse proxy that forwards all requests for /api/v1/* and rewrites them to /*.

The application itself doesn't know that but the FastAPI object which has openapi_prefix="/api/v1".

If I have an endpoint

@app.get("/hello")
def foo():
return "hello"

and I query /api/v1/hello, it works fine. If I add an extra slash at the end, a redirect occurs but tries to send the user to /hello instead of /api/v1/hello.

I'm not sure if it's a bug or if I don't use the app correctly. Maybe it would be simpler for me to make the fastapi app aware of the /api/v1 prefix and remove the rewrite rule? What do you think?

To Reproduce

Behind a reverse proxy forwarding the requests for /api/v1/* and rewriting those to /*

Create a file with:

from fastapi import FastAPI

app = FastAPI(openapi_prefix="/api/v1")

@app.get("/hello")
def read_root():
return {"Hello": "World"}

Open the browser and call the endpoint /api/v1/hello/.

It returns a 404 because there is a redirect to /hello.

But I expected the redirect to be to /api/v1/hello.

Expected behavior

The redirection shouldn't remove the openapi_prefix.

Environment

OS: Linux / Windows

FastAPI Version 0.52.0 from pip

python 3.7.4.

Issue 2:
Schema is auto-added when using file uploads with no clear reason to why

View template and re-review suggestions ✅

Try to find exiting issues/solutions ✅

Problem:

When adding a file upload using the FastAPI's File and UploadFile two schema's seem to be automatically added without any clear reason why and with seemingly no working way to replace/overwrite/remove them. As they don't provide any meaningful information for the consumers of my API I would like to replace/remove them 😅

Questions

Is this intended behaviour? (As in, shouldn't the specified responses and/or response models take precedence?)

No -> Ticket should be tagged with a 🐛

Is there a way to overwrite/remove these?

Yes! (Answered by @NicolasRondon)

Source

src/main.py

from api.http.routers import ROUTERS
from api.settings import SETTINGS

# Setting up application logger
logging.basicConfig(level=logging.DEBUG)

# Initialize application with settings
app = FastAPI(**SETTINGS["app"])

# Add the routers
[app.include_router(router) for router in ROUTERS]
# ...

src/api/http/routers/file.py

# ... imports
_dbucket = SETTINGS["backend"]["storage"]["default_bucket"]
_dfile = SETTINGS["backend"]["storage"]["default_file"]

router = APIRouter()

# ... Other routers

# router usage
@router.post(
path="/file/upload",
operation_id="api.http.routers.file.upload",
tags=["Uploads & Downloads"],
response_model=Result,
responses=FileResponses.upload_direct)
async def upload_direct(
name: str = _dfile, bucket: str = _dbucket, file: UploadFile = File(...)
):
"""Admin/debugging call for direct file upload"""
if StorageClient.lookup_file(name, bucket):
raise HTTPException(
status_code=409, detail="The file already exists"
)
else:
file.filename = name
StorageClient.upload_direct(bucket, file)
return Result(detail=[{"msg": "File uploaded sucessfully"}])

src/api/models/generic.py

from typing import List
from pydantic import BaseModel

class Message(BaseModel):
"""Generic message model"""
msg: str

class Result(BaseModel):
"""File/bucket generic result"""
detail: List[Message]

Additional information for reproduction

Python version: 3.8.7 64bit

FileResponses is just a container class holding responses as described here in docs

requirements-dump.txt