Not rendering multi-select in API doc while using Pydantic model
See original GitHub issueFirst 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
import typing
from fastapi import FastAPI, Query, Depends
from pydantic import BaseModel
from enum import Enum
app = FastAPI()
class Status(str, Enum):
SUCCESS = "SUCCESS"
REFUND = "REFUND"
FAIL = "FAIL"
CANCEL = "CANCEL"
@app.get("/working-example/")
async def root_with_normal_query_params(status_in: typing.List[Status] = Query(...)):
return {"status_inputs": status_in}
class StatusModel(BaseModel):
status_in: typing.List[Status]
@app.get("/not-working-example/")
async def root_with_pydantic(status_inputs: StatusModel = Depends()):
return {"status_inputs": status_inputs}
Description
The API docs are not generating the multi-select option while using the Pydantic model for the query/request parser.
without using Pydantic model

with using Pydantic model

Operating System
Linux
Operating System Details
No response
FastAPI Version
0.70.1
Python Version
Python 3.9.11
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
Body - Multiple Parameters - FastAPI
Now that we have seen how to use Path and Query , let's see more advanced uses of ... parameters in the function...
Read more >tiangolo/fastapi - Gitter
Add docs for correctly using FastAPI with Peewee ORM. Including how to overwrite parts of ... Has anyone achieved this sort of API...
Read more >Cool Things You Can Do With Pydantic - Medium
Pydantic models. Pydantic is a useful library for data parsing and validation. It coerces input types to the declared type (using type ...
Read more >Generate Pydantic Models from JSON in the browser : r/Python
Usually when I'm using some third party API that may or may not have documentation, I write a Pydantic model to represent the...
Read more >Ssaw.assignments module - API
I'm working on an application to perform assignments. The code below creates the assignment but ... from ssaw.models import Assignment
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You can use
dataclassfrom Pydantic.I’m kind of okay with the solution since we’re still not sure “why” FastAPI doesn’t support it - is that on purpose? Or a bug?
Also, I hope this current GH issue considers a bug - or I wrote like that in the first place, which makes me think that it is better not to close this GH issue at the moment.
I would be super happy if someone could change the label of this issue from https://github.com/tiangolo/fastapi/labels/question to https://github.com/tiangolo/fastapi/labels/bug