mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-05 07:34:12 -04:00
✨ Add docs and tests for Python 3.9 and Python 3.10 (#3712)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
committed by
GitHub
parent
83f6781037
commit
d08a062ee2
11
docs_src/query_params_str_validations/tutorial001_py310.py
Normal file
11
docs_src/query_params_str_validations/tutorial001_py310.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: str | None = None):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
11
docs_src/query_params_str_validations/tutorial002_py310.py
Normal file
11
docs_src/query_params_str_validations/tutorial002_py310.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: str | None = Query(None, max_length=50)):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
11
docs_src/query_params_str_validations/tutorial003_py310.py
Normal file
11
docs_src/query_params_str_validations/tutorial003_py310.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: str | None = Query(None, min_length=3, max_length=50)):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
13
docs_src/query_params_str_validations/tutorial004_py310.py
Normal file
13
docs_src/query_params_str_validations/tutorial004_py310.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(
|
||||
q: str | None = Query(None, min_length=3, max_length=50, regex="^fixedquery$")
|
||||
):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
11
docs_src/query_params_str_validations/tutorial007_py310.py
Normal file
11
docs_src/query_params_str_validations/tutorial007_py310.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: str | None = Query(None, title="Query string", min_length=3)):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
19
docs_src/query_params_str_validations/tutorial008_py310.py
Normal file
19
docs_src/query_params_str_validations/tutorial008_py310.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(
|
||||
q: str
|
||||
| None = Query(
|
||||
None,
|
||||
title="Query string",
|
||||
description="Query string for the items to search in the database that have a good match",
|
||||
min_length=3,
|
||||
)
|
||||
):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
11
docs_src/query_params_str_validations/tutorial009_py310.py
Normal file
11
docs_src/query_params_str_validations/tutorial009_py310.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: str | None = Query(None, alias="item-query")):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
23
docs_src/query_params_str_validations/tutorial010_py310.py
Normal file
23
docs_src/query_params_str_validations/tutorial010_py310.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(
|
||||
q: str
|
||||
| None = Query(
|
||||
None,
|
||||
alias="item-query",
|
||||
title="Query string",
|
||||
description="Query string for the items to search in the database that have a good match",
|
||||
min_length=3,
|
||||
max_length=50,
|
||||
regex="^fixedquery$",
|
||||
deprecated=True,
|
||||
)
|
||||
):
|
||||
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
return results
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: list[str] | None = Query(None)):
|
||||
query_items = {"q": q}
|
||||
return query_items
|
||||
11
docs_src/query_params_str_validations/tutorial011_py39.py
Normal file
11
docs_src/query_params_str_validations/tutorial011_py39.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: Optional[list[str]] = Query(None)):
|
||||
query_items = {"q": q}
|
||||
return query_items
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI, Query
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(q: list[str] = Query(["foo", "bar"])):
|
||||
query_items = {"q": q}
|
||||
return query_items
|
||||
Reference in New Issue
Block a user