Issue 1:
First check

[ DONE] I added a very descriptive title to this issue.

[ DONE] I used the GitHub search to find a similar issue and didn't find it.

[ DONE] I searched the FastAPI documentation, with the integrated search.

[ DONE] I already searched in Google "How to X in FastAPI" and didn't find any information.

[ DONE] I already read and followed all the tutorial in the docs and didn't find an answer.

[ DONE] I already checked if it is not related to FastAPI but to Pydantic.

[ DONE] I already checked if it is not related to FastAPI but to Swagger UI.

[ DONE] I already checked if it is not related to FastAPI but to ReDoc.

[ YES] After submitting this, I commit to one of:

Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.

I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.

Implement a Pull Request for a confirmed bug.

There is an issue when moving from default JSON responses to ORJSONResponse. When returning a Dict that uses integers as keys, default json responses will cast them to string, in order to produce valid json output. ORJSON will refuse to serialize this response.

Example

Here's a self-contained, minimal, reproducible, example with my use case:

This works:

from fastapi import FastAPI
from fastapi.responses import ORJSONResponse

app = FastAPI()

@app.get("/")
async def dict():
return {1:2}

if __name__ == "__main__":
import uvicorn
uvicorn.run("service:app", port=8001, workers=1)

But this fails:

from fastapi import FastAPI
from fastapi.responses import ORJSONResponse

app = FastAPI(default_response_class=ORJSONResponse,)

@app.get("/")
async def dict():
return {1:2}

if __name__ == "__main__":
import uvicorn
uvicorn.run("service:app", port=8001, workers=1)

You can test both behaviours using swagger UI.

Also, I don't know if there's something we can do here, since it seems to be the way ORJSON was defined, but I think we can at least add a comment about it in the docs.

Environment

OS: [e.g. Linux / Windows / macOS]: Tested on Ubuntu MATE 18.04, MacOS, and alpine linux

FastAPI Version [e.g. 0.3.0]: 0.63.0 in all cases

Python version: 3.7, 3.8 and 3.9

Issue 2:
First Check

I added a very descriptive title to this issue.

I used the GitHub search to find a similar issue and didn't find it.

I searched the FastAPI documentation, with the integrated search.

I already searched in Google "How to X in FastAPI" and didn't find any information.

I already read and followed all the tutorial in the docs and didn't find an answer.

I already checked if it is not related to FastAPI but to Pydantic.

I already checked if it is not related to FastAPI but to Swagger UI.

I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

I commit to help with one of those options 👆

Example Code

#main.py

from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi

from test_api.router import *

logger = logging.getLogger(__name__)

app = FastAPI(
title="test_API",
root_path="/test",
)

app.include_router(router)

description = """
Test API overview
"""

def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Test API",
version="0.0.1",
description=description,
routes=app.routes,
)
openapi_schema["info"]["x-logo"] = {
"url": "https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png"
}
app.openapi_schema = openapi_schema
return app.openapi_schema

# assign the customized OpenAPI schema
app.openapi = custom_openapi

#router.py

import logging

from fastapi import APIRouter

logger = logging.getLogger(__name__)

router = APIRouter(
prefix="/test",
)

@router.get(
"/health_check",
)
def root():
return {"status": "Success"}

Description

We are using FastAPI alongside ApiGateway on AWS. We have multiple APIs being handled by one Custom domain name so we are required to use API mappings with specific Paths.

With the configuration shown all the routes for the API works as well as the documentation or getting the openapi.json file. The only issue is when trying to execute the API from the docs page with the "Try it out" option. Is not adding the prefix so every request is ending up with a 404 error.

We tried working with routes as well, but this ends up duplicating the prefix and we don't want that.

After more testing we found that the issue could be related to the custom_openapi function, if we remove it, the try it out button works. But the rest of the docs does not.

Is there any kind of parameter we could use inside this definition to achieve the addition of the prefix only to the execute part without having the need to add a router since this causes the prefix to be duplicated.

The request would look like this:

curl --location --request GET 'http://127.0.0.1:9999/test/test/health_check'

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.88.0

Python Version

Python 3.8

Additional Context

No response