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.
*,
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
@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
@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
*,
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
*,
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
*,
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
*,
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
*,
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
@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
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": {
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
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": {
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
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": {
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
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": {
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
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": {
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",
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": {
"required": False,
"schema": {
"title": "Limit",
+ "maximum": 100.0,
"type": "integer",
"default": 100,
- "lte": 100,
},
"name": "limit",
"in": "query",