diff --git a/client/src/api/schema/schema.ts b/client/src/api/schema/schema.ts index a2aa6e3d6c75..f1bba9373c56 100644 --- a/client/src/api/schema/schema.ts +++ b/client/src/api/schema/schema.ts @@ -339,7 +339,7 @@ export interface paths { }; /** * Displays information about and/or content of a dataset. - * @description **Note**: Due to the multipurpose nature of this endpoint, which can receive a wild variety of parameters + * @description **Note**: Due to the multipurpose nature of this endpoint, which can receive a wide variety of parameters * and return different kinds of responses, the documentation here will be limited. * To get more information please check the source code. */ @@ -18388,6 +18388,10 @@ export interface operations { hda_ldda?: components["schemas"]["DatasetSourceType"]; /** @description The type of information about the dataset to be requested. Each of these values may require additional parameters in the request and may return different responses. */ data_type?: components["schemas"]["RequestDataType"] | null; + /** @description Maximum number of items to return. Currently only applies to `data_type=raw_data` requests */ + limit?: number | null; + /** @description Starts at the beginning skip the first ( offset - 1 ) items and begin returning at the Nth item. Currently only applies to `data_type=raw_data` requests */ + offset?: number | null; /** @description View to be passed to the serializer */ view?: string | null; /** @description Comma-separated list of keys to be passed to the serializer */ diff --git a/lib/galaxy/datatypes/dataproviders/base.py b/lib/galaxy/datatypes/dataproviders/base.py index c1239f86b9ff..a271437f184e 100644 --- a/lib/galaxy/datatypes/dataproviders/base.py +++ b/lib/galaxy/datatypes/dataproviders/base.py @@ -36,6 +36,7 @@ def stop( self ): self.endpoint = source.tell(); raise StopIteration() Building a giant list by sweeping all possible dprov classes doesn't make sense For now - I'm burying them in the class __init__s - but I don't like that """ +MAX_LIMIT = 10000 # ----------------------------------------------------------------------------- base classes @@ -233,21 +234,20 @@ class LimitedOffsetDataProvider(FilteredDataProvider): settings = {"limit": "int", "offset": "int"} # TODO: may want to squash this into DataProvider - def __init__(self, source, offset=0, limit=None, **kwargs): + def __init__(self, source, offset=0, limit=MAX_LIMIT, **kwargs): """ :param offset: the number of data to skip before providing. :param limit: the final number of data to provide. """ super().__init__(source, **kwargs) - # how many valid data to skip before we start outputing data - must be positive - # (diff to support neg. indeces - must be pos.) - self.offset = max(offset, 0) + # how many valid data to skip before we start outputting data - must be positive + self.offset = offset - # how many valid data to return - must be positive (None indicates no limit) + # how many valid data to return - must be positive + if limit is None: + limit = MAX_LIMIT self.limit = limit - if self.limit is not None: - self.limit = max(self.limit, 0) def __iter__(self): """ diff --git a/lib/galaxy/webapps/galaxy/api/datasets.py b/lib/galaxy/webapps/galaxy/api/datasets.py index 73a06eaf0d66..eba6795100fd 100644 --- a/lib/galaxy/webapps/galaxy/api/datasets.py +++ b/lib/galaxy/webapps/galaxy/api/datasets.py @@ -27,6 +27,7 @@ ) from typing_extensions import Annotated +from galaxy.datatypes.dataproviders.base import MAX_LIMIT from galaxy.schema import ( FilterQueryParams, SerializationParams, @@ -429,18 +430,35 @@ def show( "may return different responses." ), ), + limit: Annotated[ + Optional[int], + Query( + ge=1, + le=MAX_LIMIT, + description="Maximum number of items to return. Currently only applies to `data_type=raw_data` requests", + ), + ] = MAX_LIMIT, + offset: Annotated[ + Optional[int], + Query( + ge=0, + description="Starts at the beginning skip the first ( offset - 1 ) items and begin returning at the Nth item. Currently only applies to `data_type=raw_data` requests", + ), + ] = 0, serialization_params: SerializationParams = Depends(query_serialization_params), ): """ - **Note**: Due to the multipurpose nature of this endpoint, which can receive a wild variety of parameters + **Note**: Due to the multipurpose nature of this endpoint, which can receive a wide variety of parameters and return different kinds of responses, the documentation here will be limited. To get more information please check the source code. """ - exclude_params = {"hda_ldda", "data_type"} + exclude_params = {"hda_ldda", "data_type", "limit", "offset"} exclude_params.update(SerializationParams.model_fields.keys()) extra_params = get_query_parameters_from_request_excluding(request, exclude_params) - return self.service.show(trans, dataset_id, hda_ldda, serialization_params, data_type, **extra_params) + return self.service.show( + trans, dataset_id, hda_ldda, serialization_params, data_type, limit=limit, offset=offset, **extra_params + ) @router.get( "/api/datasets/{dataset_id}/content/{content_type}",