fastapi search improve model validation and add api contract tests#11549
Merged
fastapi search improve model validation and add api contract tests#11549
Conversation
Collaborator
Author
|
At this point I have now added some contract tests that catch the issue found here: #11548 |
…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.
…in AdditionalEndpointQueryOptions.
…stParams` model using `Query()` and add OpenAPI documentation tests.
…est for pagination parameter handling.
… a list in search request parameters.
…oint and update tests accordingly
…oints, introducing shared test fixtures and updating existing FastAPI tests.
…tionary and corresponding test.
…uthor_facet` as an alias for `author_key`, and enhance API contract testing with dynamic parameter generation.
6b17b73 to
7f9d60e
Compare
…` in search test.
…fields into PublicQueryOptions and add a synchronization test.
cdrini
approved these changes
Dec 17, 2025
Collaborator
cdrini
left a comment
There was a problem hiding this comment.
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) |
Collaborator
There was a problem hiding this comment.
Suggested change
| # List fields (facets) | |
| # List fields (facets). Note the examples power some of the unit tests. |
Collaborator
There was a problem hiding this comment.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11548
Closes #11587
qparameter validation intoPublicQueryOptionsfield validator and useHTTPExceptionfor errors.Closes #
Technical
Testing
Screenshot
Stakeholders