Generate RescueGroups.org API client with openapi-generator-cli#138
Open
Smoss wants to merge 3 commits into
Open
Generate RescueGroups.org API client with openapi-generator-cli#138Smoss wants to merge 3 commits into
Smoss wants to merge 3 commits into
Conversation
This is the foundation for fixing #115 (multi-species support) and addressing the failure of #124, which broke in production because the hand-rolled rescue_groups.py code emitted a request shape that the live API rejected, returning zero results. Instead of continuing to hand-roll HTTP calls, this commit introduces: - scripts/generate_rescuegroups_client.sh: regenerates the client from the api-evangelist OpenAPI spec, pinned to a specific commit SHA via gh api for reproducibility. The spec is fetched to /tmp and never written into the repo. Generator image: openapi-generator-cli:v7.23.0. - vendor/rescuegroups_client/: the generated Python client. Only the package (rescuegroups_client/) and the generated docs/ are vendored; the script also deletes CI configs, tests, build outputs, and generator metadata. The .gitignore has belt-and-suspenders rules for the same. - .gitignore: ignore rules for the generated build artefacts and the unrelated generator cruft that the tidy step may miss on a future generator version. Follow-up work needed before this can replace rescue_groups.py: - Wrap the generated client behind a PetSource adapter so main.py keeps working unchanged. - Add a live-API integration test (gated on CUTEPETSBOSTON_RESCUEGROUPS_API_KEY) so future request-shape changes are validated against the real API. - Re-introduce multi-species search using the typed SearchRequest, with the canonical body shape (species.singular, geodistance) that matches the documented example. The new client typed the search call against the spec; the search body now uses species.singular + geodistance, which matches the canonical example in the upstream spec and was the likely cause of #124 returning zero results.
This commit introduces two new files: - `vendor/__init__.py`: Initializes the vendor package. - `vendor/rescuegroups_client/__init__.py`: Initializes the generated RescueGroups.org API client package. These files lay the groundwork for integrating the new API client into the project.
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.
Summary
This is the foundation for fixing #115 (multi-species support) and addressing the production failure of #124, which broke because the hand-rolled
rescue_groups.pyemitted a request shape the live API rejected, returning zero results.Instead of continuing to hand-roll HTTP calls, this commit introduces a generated Python client for the RescueGroups.org v5 API, built from the community-maintained OpenAPI spec at https://github.com/api-evangelist/rescuegroups-org.
What's in this PR
scripts/generate_rescuegroups_client.sh: regenerates the client from the OpenAPI spec, pinned to a specific commit SHA viagh apifor reproducibility. Spec is fetched to/tmpand never written into the repo. Generator image:openapi-generator-cli:v7.23.0.vendor/rescuegroups_client/: the generated Python client. Only the package (rescuegroups_client/) and the generateddocs/are vendored; the script deletes CI configs, tests, build outputs, and generator metadata..gitignore: ignore rules for the generated build artefacts and the unrelated generator cruft, in case a future generator version puts files in a new place.Why this matters for #124
The merged
rescue_groups.pyfrom #124 built a search request withfieldName: "species.plural", criteria: "dogs"/"cats"and afilterProcessing: "1 OR 2"filter array. The live API returned zero results, andpick_petraisedValueError("No elligible pet found")four minutes after the merge.The canonical example in the upstream spec uses a different shape:
{ "data": { "filters": [ {"fieldName": "species.singular", "operation": "equal", "criteria": "Dog"} ], "geodistance": {"postalcode": "90210", "miles": 25} } }The new generated client uses this canonical shape. The likely cause of #124's failure was a field name mismatch (
species.pluralvs.species.singular) or thefilterProcessingOR syntax not being accepted by the live API on the species-less/available/haspicendpoint.Why it failed in CI
The unit tests for #124 mocked the HTTP session and only checked the request shape, not the live response. The
dev.ymlworkflow runs with--debugsources --debugposters, which short-circuits to aSourceManualfixture — the live API was never exercised. This PR doesn't fix that, but the follow-up work below will.Follow-up (not in this PR)
Before this can replace the existing
rescue_groups.py, we need:adoption_sources/that adapts the generated client to the existingPetSourceinterface somain.pykeeps working unchanged.CUTEPETSBOSTON_RESCUEGROUPS_API_KEY, asserting the actual response — not just the request shape. This is the test that was missing for Add cats to adoptable pet pool (closes #115) #124.SearchRequestwith the canonical body shape.Test plan
python -m pip install -e vendor/rescuegroups_clientsucceeds in a fresh venv.from rescuegroups_client.api.animals_api import AnimalsApisucceeds.SearchRequestwithSearchFilter(field_name='species.singular', ...)and serializing to dict produces the canonical body shape.git statusshows onlydocs/andrescuegroups_client/undervendor/rescuegroups_client/— no CI configs, no tests, no build artefacts.find . -name openapi.ymlreturns nothing (spec was never written into the repo).Testsworkflow passes (only the modified.gitignoreshould trigger).