diff --git a/src/routers/resource_ai_asset_router.py b/src/routers/resource_ai_asset_router.py index 3681422f..98335ad9 100644 --- a/src/routers/resource_ai_asset_router.py +++ b/src/routers/resource_ai_asset_router.py @@ -1,5 +1,3 @@ -from typing import Annotated - import requests from fastapi import APIRouter, HTTPException, status, Path from fastapi.responses import Response @@ -50,16 +48,10 @@ def get_resource_content_func(self, default: bool): """ def get_resource_content( - identifier: Annotated[ - str, Path(description=f"The identifier of the {self.resource_name}") # type: ignore - ], - distribution_idx: Annotated[ - int, - Path( - description=f"The index of the distribution within the " f"{self.resource_name}" - ), # type: ignore - ], - default: bool = False, + identifier: str = Path(description=f"The identifier of the {self.resource_name}"), + distribution_idx: int = Path( + description=f"The index of the distribution within the {self.resource_name}" + ), ): metadata: AIAsset = self.get_resource( identifier=identifier, schema="aiod", platform=None @@ -106,11 +98,9 @@ def get_resource_content( raise _wrap_as_http_exception(exc) def get_resource_content_default( - identifier: Annotated[ - str, Path(description=f"The identifier of the {self.resource_name}") # type: ignore - ] + identifier: str = Path(description=f"The identifier of the {self.resource_name}"), ): - return get_resource_content(identifier=identifier, distribution_idx=0, default=True) + return get_resource_content(identifier=identifier, distribution_idx=0) if default: return get_resource_content_default diff --git a/src/routers/resource_router.py b/src/routers/resource_router.py index b965d1a4..96b7ed68 100644 --- a/src/routers/resource_router.py +++ b/src/routers/resource_router.py @@ -269,9 +269,9 @@ def get_resource_count_func(self): """ def get_resource_count( - detailed: Annotated[ - bool, Query(description="If true, a more detailed output is returned.") - ] = False + detailed: bool = Query( + description="If true, a more detailed output is returned.", default=False + ) ): try: with DbSession() as session: @@ -308,13 +308,10 @@ def get_platform_resources_func(self): """ def get_resources( - platform: Annotated[ - str, - Path( - description="Return resources of this platform", - example="huggingface", - ), - ], + platform: str = Path( + description="Return resources of this platform", + example="huggingface", + ), pagination: Pagination = Depends(Pagination), schema: self._possible_schemas_type = "aiod", # type:ignore ): @@ -348,13 +345,10 @@ def get_platform_resource_func(self): def get_resource( identifier: str, - platform: Annotated[ - str, - Path( - description="Return resources of this platform", - example="huggingface", - ), - ], + platform: str = Path( + description="Return resources of this platform", + example="huggingface", + ), schema: self._possible_schemas_type = "aiod", # type:ignore ): return self.get_resource(identifier=identifier, schema=schema, platform=platform) diff --git a/src/routers/search_router.py b/src/routers/search_router.py index a8e91426..5b191d9e 100644 --- a/src/routers/search_router.py +++ b/src/routers/search_router.py @@ -1,5 +1,5 @@ import abc -from typing import TypeVar, Generic, Any, Type, Annotated, Literal +from typing import TypeVar, Generic, Any, Type, Literal from fastapi import APIRouter, HTTPException, Query from pydantic import BaseModel @@ -76,39 +76,32 @@ def create(self, url_prefix: str) -> APIRouter: # response_model=SearchResult[read_class], # This gives errors, so not used. ) def search( - search_query: Annotated[ - str, - Query( - description="Text you wish to find. It is used in an ElasticSearch match " - "query.", - examples=["Name of the resource"], - ), - ], - search_fields: Annotated[ # type: ignore - list[indexed_fields] | None, - Query( - description="Search in these fields. If empty, the query will be matched " - "against all fields. Do not use the '--' option in Swagger, it is a Swagger " - "artifact.", - ), - ] = None, - platforms: Annotated[ - list[str] | None, - Query( - description="Search for resources of these platforms. If empty, results from " - "all platforms will be returned.", - examples=["huggingface", "openml"], - ), - ] = None, - limit: Annotated[int | None, Query(ge=1, le=LIMIT_MAX)] = 10, - offset: Annotated[int | None, Query(ge=0)] = 0, - get_all: Annotated[ - bool, - Query( - description="If true, a request to the database is made to retrieve all data. " - "If false, only the indexed information is returned." - ), - ] = False, + search_query: str = Query( + ..., + description="Text you wish to find. It is used in an ElasticSearch match " "query.", + examples=["Name of the resource"], + ), + search_fields: list[indexed_fields] # type: ignore + | None = Query( + description="Search in these fields. If empty, the query will be matched " + "against all fields. Do not use the '--' option in Swagger, it is a Swagger " + "artifact.", + default=None, + ), + platforms: list[str] + | None = Query( + description="Search for resources of these platforms. If empty, results from " + "all platforms will be returned.", + examples=["huggingface", "openml"], + default=None, + ), + limit: int | None = Query(ge=1, le=LIMIT_MAX, default=10), + offset: int | None = Query(ge=0, default=0), + get_all: bool = Query( + description="If true, a request to the database is made to retrieve all data. " + "If false, only the indexed information is returned.", + default=False, + ), ): try: with DbSession() as session: diff --git a/src/routers/upload_router_huggingface.py b/src/routers/upload_router_huggingface.py index 5797530f..9fd50fbc 100644 --- a/src/routers/upload_router_huggingface.py +++ b/src/routers/upload_router_huggingface.py @@ -11,7 +11,6 @@ def create(self, url_prefix: str) -> APIRouter: @router.post(url_prefix + "/upload/datasets/{identifier}/huggingface", tags=["upload"]) def huggingFaceUpload( identifier: int = Path( - ..., description="The AIoD dataset identifier", ), file: UploadFile = File(