diff --git a/openlibrary/fastapi/search.py b/openlibrary/fastapi/search.py index 8d4ffedf7cd..0111cb88166 100644 --- a/openlibrary/fastapi/search.py +++ b/openlibrary/fastapi/search.py @@ -1,7 +1,7 @@ from __future__ import annotations import json -from typing import Annotated, Any +from typing import Annotated, Any, Literal from fastapi import APIRouter, Depends, Query, Request from fastapi.responses import JSONResponse @@ -50,8 +50,8 @@ class PublicQueryOptions(BaseModel): person: str | None = None time: str | None = None # from workscheme facet_fields - has_fulltext: bool | None = None - public_scan_b: bool | None = None + has_fulltext: Literal['true', 'false'] | None = None + public_scan_b: Literal['true', 'false'] | None = None """ The day will come when someone asks, why do we have Field wrapping Query diff --git a/openlibrary/tests/fastapi/test_search.py b/openlibrary/tests/fastapi/test_search.py index 772e7176910..75ba6ac254f 100644 --- a/openlibrary/tests/fastapi/test_search.py +++ b/openlibrary/tests/fastapi/test_search.py @@ -189,9 +189,9 @@ def test_pagination_validation_errors(self, client, mock_work_search, params): [ # Case 1: publisher should pass as a string ({'publisher': 'Lab of Thought'}, 'publisher', 'Lab of Thought'), - # Case 2: has_fulltext should pass as a boolean - ({'has_fulltext': 'true'}, 'has_fulltext', True), - ({'has_fulltext': 'false'}, 'has_fulltext', False), + # Case 2: has_fulltext should pass as a string + ({'has_fulltext': 'true'}, 'has_fulltext', 'true'), + ({'has_fulltext': 'false'}, 'has_fulltext', 'false'), ], ) def test_search_parameter_types(