Skip to content

Commit d192142

Browse files
jrycwtiangolo
andauthored
📝 Fix docs for Pydantic's fields using le (lte is invalid, use le ) (#207)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
1 parent beb7a24 commit d192142

File tree

14 files changed

+24
-30
lines changed

14 files changed

+24
-30
lines changed

docs/tutorial/fastapi/limit-and-offset.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ We want to allow clients to set different `offset` and `limit` values.
4242

4343
But we don't want them to be able to set a `limit` of something like `9999`, that's over `9000`! 😱
4444

45-
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`.
45+
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`.
4646

4747
This way, a client can decide to take fewer heroes if they want, but not more.
4848

docs_src/tutorial/fastapi/app_testing/tutorial001/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def read_heroes(
6666
*,
6767
session: Session = Depends(get_session),
6868
offset: int = 0,
69-
limit: int = Query(default=100, lte=100),
69+
limit: int = Query(default=100, le=100),
7070
):
7171
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
7272
return heroes

docs_src/tutorial/fastapi/delete/tutorial001.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_hero(hero: HeroCreate):
5858

5959

6060
@app.get("/heroes/", response_model=List[HeroRead])
61-
def read_heroes(offset: int = 0, limit: int = Query(default=100, lte=100)):
61+
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
6262
with Session(engine) as session:
6363
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
6464
return heroes

docs_src/tutorial/fastapi/limit_and_offset/tutorial001.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create_hero(hero: HeroCreate):
5252

5353

5454
@app.get("/heroes/", response_model=List[HeroRead])
55-
def read_heroes(offset: int = 0, limit: int = Query(default=100, lte=100)):
55+
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
5656
with Session(engine) as session:
5757
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
5858
return heroes

docs_src/tutorial/fastapi/relationships/tutorial001.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def read_heroes(
104104
*,
105105
session: Session = Depends(get_session),
106106
offset: int = 0,
107-
limit: int = Query(default=100, lte=100),
107+
limit: int = Query(default=100, le=100),
108108
):
109109
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
110110
return heroes
@@ -158,7 +158,7 @@ def read_teams(
158158
*,
159159
session: Session = Depends(get_session),
160160
offset: int = 0,
161-
limit: int = Query(default=100, lte=100),
161+
limit: int = Query(default=100, le=100),
162162
):
163163
teams = session.exec(select(Team).offset(offset).limit(limit)).all()
164164
return teams

docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def read_heroes(
6666
*,
6767
session: Session = Depends(get_session),
6868
offset: int = 0,
69-
limit: int = Query(default=100, lte=100),
69+
limit: int = Query(default=100, le=100),
7070
):
7171
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
7272
return heroes

docs_src/tutorial/fastapi/teams/tutorial001.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def read_heroes(
9595
*,
9696
session: Session = Depends(get_session),
9797
offset: int = 0,
98-
limit: int = Query(default=100, lte=100),
98+
limit: int = Query(default=100, le=100),
9999
):
100100
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
101101
return heroes
@@ -149,7 +149,7 @@ def read_teams(
149149
*,
150150
session: Session = Depends(get_session),
151151
offset: int = 0,
152-
limit: int = Query(default=100, lte=100),
152+
limit: int = Query(default=100, le=100),
153153
):
154154
teams = session.exec(select(Team).offset(offset).limit(limit)).all()
155155
return teams

docs_src/tutorial/fastapi/update/tutorial001.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_hero(hero: HeroCreate):
5858

5959

6060
@app.get("/heroes/", response_model=List[HeroRead])
61-
def read_heroes(offset: int = 0, limit: int = Query(default=100, lte=100)):
61+
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
6262
with Session(engine) as session:
6363
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
6464
return heroes

tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ def test_tutorial(clear_sqlmodel):
5757
assert response.status_code == 404, response.text
5858

5959
response = client.get("/openapi.json")
60-
data = response.json()
6160
assert response.status_code == 200, response.text
62-
assert data == {
61+
assert response.json() == {
6362
"openapi": "3.0.2",
6463
"info": {"title": "FastAPI", "version": "0.1.0"},
6564
"paths": {
@@ -82,9 +81,9 @@ def test_tutorial(clear_sqlmodel):
8281
"required": False,
8382
"schema": {
8483
"title": "Limit",
84+
"maximum": 100.0,
8585
"type": "integer",
8686
"default": 100,
87-
"lte": 100,
8887
},
8988
"name": "limit",
9089
"in": "query",

tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ def test_tutorial(clear_sqlmodel):
6262
assert data[0]["name"] == hero2_data["name"]
6363

6464
response = client.get("/openapi.json")
65-
data = response.json()
6665
assert response.status_code == 200, response.text
67-
assert data == {
66+
assert response.json() == {
6867
"openapi": "3.0.2",
6968
"info": {"title": "FastAPI", "version": "0.1.0"},
7069
"paths": {
@@ -87,9 +86,9 @@ def test_tutorial(clear_sqlmodel):
8786
"required": False,
8887
"schema": {
8988
"title": "Limit",
89+
"maximum": 100.0,
9090
"type": "integer",
9191
"default": 100,
92-
"lte": 100,
9392
},
9493
"name": "limit",
9594
"in": "query",

tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ def test_tutorial(clear_sqlmodel):
105105
assert len(data) == 1
106106

107107
response = client.get("/openapi.json")
108-
data = response.json()
109108
assert response.status_code == 200, response.text
110-
assert data == {
109+
assert response.json() == {
111110
"openapi": "3.0.2",
112111
"info": {"title": "FastAPI", "version": "0.1.0"},
113112
"paths": {
@@ -130,9 +129,9 @@ def test_tutorial(clear_sqlmodel):
130129
"required": False,
131130
"schema": {
132131
"title": "Limit",
132+
"maximum": 100.0,
133133
"type": "integer",
134134
"default": 100,
135-
"lte": 100,
136135
},
137136
"name": "limit",
138137
"in": "query",
@@ -329,9 +328,9 @@ def test_tutorial(clear_sqlmodel):
329328
"required": False,
330329
"schema": {
331330
"title": "Limit",
331+
"maximum": 100.0,
332332
"type": "integer",
333333
"default": 100,
334-
"lte": 100,
335334
},
336335
"name": "limit",
337336
"in": "query",

tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ def test_tutorial(clear_sqlmodel):
5757
assert response.status_code == 404, response.text
5858

5959
response = client.get("/openapi.json")
60-
data = response.json()
6160
assert response.status_code == 200, response.text
62-
assert data == {
61+
assert response.json() == {
6362
"openapi": "3.0.2",
6463
"info": {"title": "FastAPI", "version": "0.1.0"},
6564
"paths": {
@@ -82,9 +81,9 @@ def test_tutorial(clear_sqlmodel):
8281
"required": False,
8382
"schema": {
8483
"title": "Limit",
84+
"maximum": 100.0,
8585
"type": "integer",
8686
"default": 100,
87-
"lte": 100,
8887
},
8988
"name": "limit",
9089
"in": "query",

tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ def test_tutorial(clear_sqlmodel):
9292
assert len(data) == 1
9393

9494
response = client.get("/openapi.json")
95-
data = response.json()
9695
assert response.status_code == 200, response.text
97-
assert data == {
96+
assert response.json() == {
9897
"openapi": "3.0.2",
9998
"info": {"title": "FastAPI", "version": "0.1.0"},
10099
"paths": {
@@ -117,9 +116,9 @@ def test_tutorial(clear_sqlmodel):
117116
"required": False,
118117
"schema": {
119118
"title": "Limit",
119+
"maximum": 100.0,
120120
"type": "integer",
121121
"default": 100,
122-
"lte": 100,
123122
},
124123
"name": "limit",
125124
"in": "query",
@@ -316,9 +315,9 @@ def test_tutorial(clear_sqlmodel):
316315
"required": False,
317316
"schema": {
318317
"title": "Limit",
318+
"maximum": 100.0,
319319
"type": "integer",
320320
"default": 100,
321-
"lte": 100,
322321
},
323322
"name": "limit",
324323
"in": "query",

tests/test_tutorial/test_fastapi/test_update/test_tutorial001.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ def test_tutorial(clear_sqlmodel):
6464
assert response.status_code == 404, response.text
6565

6666
response = client.get("/openapi.json")
67-
data = response.json()
6867
assert response.status_code == 200, response.text
69-
assert data == {
68+
assert response.json() == {
7069
"openapi": "3.0.2",
7170
"info": {"title": "FastAPI", "version": "0.1.0"},
7271
"paths": {
@@ -89,9 +88,9 @@ def test_tutorial(clear_sqlmodel):
8988
"required": False,
9089
"schema": {
9190
"title": "Limit",
91+
"maximum": 100.0,
9292
"type": "integer",
9393
"default": 100,
94-
"lte": 100,
9594
},
9695
"name": "limit",
9796
"in": "query",

0 commit comments

Comments
 (0)