📝 Fix docs for Pydantic's fields using le
(lte
is invalid, use le
) (#207)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
beb7a24275
commit
d192142eb9
@ -42,7 +42,7 @@ We want to allow clients to set different `offset` and `limit` values.
|
||||
|
||||
But we don't want them to be able to set a `limit` of something like `9999`, that's over `9000`! 😱
|
||||
|
||||
So, to prevent it, we add additional validation to the `limit` query parameter, declaring that it has to be **l**ess **t**han or **e**qual to `100` with `lte=100`.
|
||||
So, to prevent it, we add additional validation to the `limit` query parameter, declaring that it has to be **l**ess than or **e**qual to `100` with `le=100`.
|
||||
|
||||
This way, a client can decide to take fewer heroes if they want, but not more.
|
||||
|
||||
|
@ -66,7 +66,7 @@ def read_heroes(
|
||||
*,
|
||||
session: Session = Depends(get_session),
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, lte=100),
|
||||
limit: int = Query(default=100, le=100),
|
||||
):
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
|
@ -58,7 +58,7 @@ def create_hero(hero: HeroCreate):
|
||||
|
||||
|
||||
@app.get("/heroes/", response_model=List[HeroRead])
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, lte=100)):
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
|
||||
with Session(engine) as session:
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
|
@ -52,7 +52,7 @@ def create_hero(hero: HeroCreate):
|
||||
|
||||
|
||||
@app.get("/heroes/", response_model=List[HeroRead])
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, lte=100)):
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
|
||||
with Session(engine) as session:
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
|
@ -104,7 +104,7 @@ def read_heroes(
|
||||
*,
|
||||
session: Session = Depends(get_session),
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, lte=100),
|
||||
limit: int = Query(default=100, le=100),
|
||||
):
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
@ -158,7 +158,7 @@ def read_teams(
|
||||
*,
|
||||
session: Session = Depends(get_session),
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, lte=100),
|
||||
limit: int = Query(default=100, le=100),
|
||||
):
|
||||
teams = session.exec(select(Team).offset(offset).limit(limit)).all()
|
||||
return teams
|
||||
|
@ -66,7 +66,7 @@ def read_heroes(
|
||||
*,
|
||||
session: Session = Depends(get_session),
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, lte=100),
|
||||
limit: int = Query(default=100, le=100),
|
||||
):
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
|
@ -95,7 +95,7 @@ def read_heroes(
|
||||
*,
|
||||
session: Session = Depends(get_session),
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, lte=100),
|
||||
limit: int = Query(default=100, le=100),
|
||||
):
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
@ -149,7 +149,7 @@ def read_teams(
|
||||
*,
|
||||
session: Session = Depends(get_session),
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, lte=100),
|
||||
limit: int = Query(default=100, le=100),
|
||||
):
|
||||
teams = session.exec(select(Team).offset(offset).limit(limit)).all()
|
||||
return teams
|
||||
|
@ -58,7 +58,7 @@ def create_hero(hero: HeroCreate):
|
||||
|
||||
|
||||
@app.get("/heroes/", response_model=List[HeroRead])
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, lte=100)):
|
||||
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
|
||||
with Session(engine) as session:
|
||||
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
|
||||
return heroes
|
||||
|
@ -57,9 +57,8 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert response.status_code == 404, response.text
|
||||
|
||||
response = client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert response.status_code == 200, response.text
|
||||
assert data == {
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
@ -82,9 +81,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
@ -62,9 +62,8 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert data[0]["name"] == hero2_data["name"]
|
||||
|
||||
response = client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert response.status_code == 200, response.text
|
||||
assert data == {
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
@ -87,9 +86,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
@ -105,9 +105,8 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert len(data) == 1
|
||||
|
||||
response = client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert response.status_code == 200, response.text
|
||||
assert data == {
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
@ -130,9 +129,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
@ -329,9 +328,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
@ -57,9 +57,8 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert response.status_code == 404, response.text
|
||||
|
||||
response = client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert response.status_code == 200, response.text
|
||||
assert data == {
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
@ -82,9 +81,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
@ -92,9 +92,8 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert len(data) == 1
|
||||
|
||||
response = client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert response.status_code == 200, response.text
|
||||
assert data == {
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
@ -117,9 +116,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
@ -316,9 +315,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
@ -64,9 +64,8 @@ def test_tutorial(clear_sqlmodel):
|
||||
assert response.status_code == 404, response.text
|
||||
|
||||
response = client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert response.status_code == 200, response.text
|
||||
assert data == {
|
||||
assert response.json() == {
|
||||
"openapi": "3.0.2",
|
||||
"info": {"title": "FastAPI", "version": "0.1.0"},
|
||||
"paths": {
|
||||
@ -89,9 +88,9 @@ def test_tutorial(clear_sqlmodel):
|
||||
"required": False,
|
||||
"schema": {
|
||||
"title": "Limit",
|
||||
"maximum": 100.0,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"lte": 100,
|
||||
},
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
Loading…
x
Reference in New Issue
Block a user