Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tutorial/fastapi/limit-and-offset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs_src/tutorial/fastapi/app_testing/tutorial001/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs_src/tutorial/fastapi/delete/tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs_src/tutorial/fastapi/limit_and_offset/tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs_src/tutorial/fastapi/relationships/tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs_src/tutorial/fastapi/teams/tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs_src/tutorial/fastapi/update/tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down