Issue 1:
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

from typing import Tuple
from fastapi import FastAPI
from pydantic import BaseModel

class FooArgs(BaseModel):
bars: Tuple[str, str]

app = FastAPI()

@app.post("/foo")
def foo(args: FooArgs):
...

Description

If you try to retrieve the /openapi.json, the FooArgs get a validation error:

File ".../lib/python3.9/site-packages/fastapi/openapi/utils.py", line 410, in get_openapi
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for OpenAPI
components -> schemas -> FooArgs -> properties -> bars -> items
value is not a valid dict (type=type_error.dict)
components -> schemas -> FooArgs -> $ref
field required (type=value_error.missing)

This error is new to fastapi>=0.68, it does not happen with fastapi==0.67.0.

I think this is related to Pydantic coercing Tuple[str, str] into Dict[str, str] somewhere?

Things that don't cause this error:

class FooArgs(BaseModel):
bars: Tuple[str]

class FooArgs(BaseModel):
bars: Tuple[str, ...]

This that do cause this error:

class FooArgs(BaseModel):
bars: Tuple[str, str]

class FooArgs(BaseModel):
bars: Tuple[int, str]

class FooArgs(BaseModel):
bars: Tuple[str, str, str] # etc.

Operating System

macOS

Operating System Details

No response

FastAPI Version

0.68.1

Python Version

3.9.1 (also seeing this in 3.8.*)

Additional Context

Seems pretty likely that this commit introduced it, but there's a lot going on so I'm not sure where:

97fa743#diff-4939896f79697822446463d5d6dfbf7a0ea5805c46565d355c7305d86f3405c7

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

import uvicorn
from fastapi import FastAPI, Form

app = FastAPI()

@app.post("/")
def hello(arg: tuple[int, int] = Form(...)) -> str:
pass

if __name__ == "__main__":
uvicorn.run("main:app", port=8080)

Description

Run pip install uvicorn fastapi==0.68.0.

Run python ./main.py

Hit localhost:8080/docs, observe internal server error with below validation errors:

pydantic.error_wrappers.ValidationError: 2 validation errors for OpenAPI
components -> schemas -> Body_hello__post -> properties -> arg -> items
value is not a valid dict (type=type_error.dict)
components -> schemas -> Body_hello__post -> $ref
field required (type=value_error.missing)

Run pip install fastapi==0.67.0

Hit localhost:8080/docs, observe that endpoint documentation is successfully generated.

Operating System

Linux

Operating System Details

Ubuntu 20.04

FastAPI Version

0.68.0 has bug, 0.67.0 does not have bug.

Python Version

3.9

Additional Context

Any use of tuple in an input (Form, and BaseModel as JSON) or output (BaseModel as JSON) results in above error.