Cannot declare parameters to receive multiples values with pydantic BaseModel and Depends
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
from typing import Optional, List
from fastapi import FastAPI, Depends, Query
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
relates_to: List[int] = Query(...)
@app.get("/items/")
async def sample_get_items(
item: Item = Depends()
):
return "ok"
Description
This code is based on the samples in the fastapi site.
The problem is in the parameter relates_to
. This parameter not appears in the /docs as a parameter because this is of the tytpe List[int]
I need, by this way, declaring parameters for a endpoint thought a pydantic.BaseModel, that have possibility to receive multiple values.
But the way it’s written in the example, it doesn’t work, either by sending
/item/?relates_to=10&relates_to=11&relates_to=12
or /item/?relates_to=[10,11,12]
or other way…
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.68.1
Python Version
3.9.5
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top Results From Across the Web
FastAPI - GET Request with Pydantic List field - Stack Overflow
When you declare a List field in the Pydantic model, ... and appear multiple times in the URL (in others words, to receive...
Read more >How to Validate Your Data with Custom Validators of Pydantic ...
By default, the values argument of a validator only stores the fields that have already been validated. Which fields are available in values...
Read more >Body - Nested Models - FastAPI
To declare types that have type parameters (internal types), like list ... Union from fastapi import FastAPI from pydantic import BaseModel app =...
Read more >How we validate input data using pydantic
We use the Python package pydantic for fast and easy validation of ... The second argument is the value to validate, and can...
Read more >Many-To-Many Relationships In FastAPI - GormAnalysis
This time we set up three models that mimic our database models. So, how does a pydantic model get serialized to JSON? Well,...
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 FreeTop 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
Top GitHub Comments
How this #question can be transformed in a #issue ?
I undertand, but is the only way that this works in a Pydantic model (see image) to be simple