Skip to content

fastapi search improve model validation and add api contract tests#11549

Merged
cdrini merged 25 commits intomasterfrom
fastapi_search_improve_model_validation
Dec 17, 2025
Merged

fastapi search improve model validation and add api contract tests#11549
cdrini merged 25 commits intomasterfrom
fastapi_search_improve_model_validation

Conversation

@RayBB
Copy link
Collaborator

@RayBB RayBB commented Dec 5, 2025

Closes #11548
Closes #11587

  • move processing of 'fields' queryparam to pydantic
  • remove mode, it's already default
  • refactor: Move q parameter validation into PublicQueryOptions field validator and use HTTPException for errors.

Closes #

Technical

Testing

Screenshot

Stakeholders

@RayBB
Copy link
Collaborator Author

RayBB commented Dec 6, 2025

At this point I have now added some contract tests that catch the issue found here: #11548
The tests for this will be failing until the above PR is merged.

@RayBB RayBB changed the title fastapi search improve model validation fastapi search improve model validation and add api contract tests Dec 6, 2025
RayBB added 21 commits December 12, 2025 11:19
…ld validator and use `HTTPException` for errors.
…e search endpoint and include new tests for valid and invalid JSON inputs.
…and remove manual parsing from `search_json` endpoint.
…stParams` model using `Query()` and add OpenAPI documentation tests.
…oints, introducing shared test fixtures and updating existing FastAPI tests.
…uthor_facet` as an alias for `author_key`, and enhance API contract testing with dynamic parameter generation.
@RayBB RayBB force-pushed the fastapi_search_improve_model_validation branch from 6b17b73 to 7f9d60e Compare December 12, 2025 19:23
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Tested on testing and the searches that were previously failing now return results. Great work on all the tests as well!



@router.get("/search.json")
# List fields (facets)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# List fields (facets)
# List fields (facets). Note the examples power some of the unit tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't bother since the unit tests powered by the examples will be deleted once the webpy endpoint is deleted, and the examples don't really need justification.

@cdrini cdrini merged commit c0298b9 into master Dec 17, 2025
8 checks passed
@cdrini cdrini deleted the fastapi_search_improve_model_validation branch December 17, 2025 18:11
mystic-06 pushed a commit to mystic-06/openlibrary that referenced this pull request Dec 24, 2025
…nternetarchive#11549)

* move processing of 'fields' queryparam to pydantic

* remove mode, it's already default

* refactor: Move `q` parameter validation into `PublicQueryOptions` field validator and use `HTTPException` for errors.

* feat: Add JSON parsing error handling for the `query` parameter in the search endpoint and include new tests for valid and invalid JSON inputs.

* feat: Add JSON query parameter with validation to `WorkSearchScheme` and remove manual parsing from `search_json` endpoint.

* refactor: encapsulate sort and spellcheck_count query parameters within AdditionalEndpointQueryOptions.

* refactor: Unify search endpoint parameters into a single `SearchRequestParams` model using `Query()` and add OpenAPI documentation tests.

* refactor: Exclude offset from the search query dictionary and add a test for pagination parameter handling.

* feat: add description and examples to the search language parameter

* feat: Add descriptions and examples to search query facet fields.

* move q back up

* refactor: simplify `Field` default assignments and ensure sorted default `fields`

* refactor: replace HTTPException with ValueError in Pydantic field validators

* docs: add "search" tag to `/search.json` endpoint

* feat: Use BeforeValidator to parse comma-separated fields string into a list in search request parameters.

* feat: Parse search query parameter as a JSON dictionary and refactor its validation.

* test: replace query alias test with precedence test for search parameters

* feat: introduce Pydantic SearchResponse model for `/search.json` endpoint and update tests accordingly

* feat: Add API contract tests to compare FastAPI and webpy search endpoints, introducing shared test fixtures and updating existing FastAPI tests.

* feat: Remove explicit `page` and `limit` addition to search query dictionary and corresponding test.

* feat: Standardize boolean query parameters to string literals, add `author_facet` as an alias for `author_key`, and enhance API contract testing with dynamic parameter generation.

* add all search fields programatically

* test: rename arbitrary query parameter `osp_count` to `osp_count_fake` in search test.

* refactor: Remove dynamic field addition by inlining WorkSearchScheme fields into PublicQueryOptions and add a synchronization test.

* feat: refactor work search query parameter handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search API errors

2 participants