Skip to content

Commit dadea58

Browse files
committed
fix op api license endpoint limit and offset parameters
1 parent 2cddaa5 commit dadea58

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

docs/OperationsAPI.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,21 @@ paths:
277277
- "licenses"
278278
operationId: getLicenses
279279
parameters:
280-
- $ref: "#/components/parameters/limit_query_param_licenses_endpoint"
281-
- $ref: "#/components/parameters/offset"
280+
- name: offset
281+
in: query
282+
description: Number of items to skip for pagination.
283+
required: false
284+
schema:
285+
type: string
286+
default: "0"
287+
- name: limit
288+
in: query
289+
description: Maximum number of items to return.
290+
required: false
291+
schema:
292+
type: string
293+
default: "50"
294+
example: "100"
282295
- $ref: "#/components/parameters/search_text_query_param_license"
283296
- $ref: "#/components/parameters/license_is_spdx_query_param"
284297
security:

functions-python/operations_api/src/feeds_operations/impl/licenses_api_impl.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LicensesApiImpl(BaseLicensesApi):
4040
"""
4141

4242
@with_db_session
43-
async def get_license(
43+
def handle_get_license(
4444
self,
4545
id: StrictStr,
4646
db_session: Session = None,
@@ -59,11 +59,21 @@ async def get_license(
5959
# Build Pydantic model from ORM object attributes
6060
return LicenseWithRulesImpl.from_orm(license_orm)
6161

62+
async def get_license(
63+
self,
64+
id: StrictStr,
65+
) -> LicenseWithRules:
66+
"""Get the specified license from the Mobility Database.
67+
68+
Raises 404 if the license is not found.
69+
"""
70+
return self.handle_get_license(id)
71+
6272
@with_db_session
63-
async def get_licenses(
73+
def handle_get_licenses(
6474
self,
65-
limit: int,
66-
offset: int,
75+
offset: str = "0",
76+
limit: str = "100",
6777
search_query: Optional[StrictStr] = None,
6878
is_spdx: Optional[bool] = None,
6979
db_session: Session = None,
@@ -83,6 +93,8 @@ async def get_licenses(
8393
is_spdx,
8494
)
8595

96+
limit_int = int(limit)
97+
offset_int = int(offset)
8698
query = db_session.query(OrmLicense)
8799

88100
# Text search by name or id
@@ -101,9 +113,24 @@ async def get_licenses(
101113
if is_spdx is not None:
102114
query = query.filter(OrmLicense.is_spdx == is_spdx)
103115

104-
query = query.order_by(OrmLicense.id).offset(offset).limit(limit)
116+
query = query.order_by(OrmLicense.id).offset(offset_int).limit(limit_int)
105117
items: List[OrmLicense] = query.all()
106118

107119
logging.info("Fetched %d licenses", len(items))
108120

109121
return [LicenseBaseImpl.from_orm(item) for item in items]
122+
123+
async def get_licenses(
124+
self,
125+
offset: str = "0",
126+
limit: str = "100",
127+
search_query: Optional[StrictStr] = None,
128+
is_spdx: Optional[bool] = None,
129+
) -> List[LicenseBase]:
130+
"""Get the list of licenses from the Mobility Database.
131+
132+
Supports pagination via `limit` and `offset`, optional
133+
case-insensitive text search on license name / id, and
134+
optional filtering by SPDX status.
135+
"""
136+
return self.handle_get_licenses(offset, limit, search_query, is_spdx)

0 commit comments

Comments
 (0)