Repository navigation
feat: add CommonGrants FastAPI API template - #1
Merged
Merged
Conversation
Following PORTING §1 as written made the kept test suites fail at collection with KeyError: 'DATABASE_URL', because they and the OpenAPI export import api.py, where the wiring reads the variable. §1 now says to set it wherever they run, CI included, and to connect on the first query so the stub-repository suites never need a database. The fixture deletion step names the export script, which still imported fixture_repository.
karinamzalez
requested changes
Oct 20, 2026
| A missing or inverted bound is unusable in the same way. Taken literally, an | ||
| inverted `between` would match nothing and `outside` every record. | ||
| """ | ||
| if value is None or low is None or high is None or low > high: |
There was a problem hiding this comment.
Suggestion: what do you think about treating a missing closeDateRange bound as open-ended? Then {"min": X} would mean “closes on or after X”.
Collaborator
Author
There was a problem hiding this comment.
Core's DateRangeFilter requires both min and max, so a one-sided range isn't valid there, and making it open-ended would be a Core change rather than a template one. Could be worth proposing for Core, though.
karinamzalez
approved these changes
Oct 20, 2026
karinamzalez
left a comment
There was a problem hiding this comment.
Worth a look:
- /docs loads JavaScript from jsdelivr into the API’s own origin, with no integrity check (SRI) and only a major-version pin (src/app.ts:61). It’s documented in PORTING §9, but the README endpoint table could mention it too, since that’s what most people read.
- (minor) url: "/openapi.json" is an absolute path (src/app.ts:61). If the app is mounted under a prefix or behind a path-rewriting proxy, the page loads but can’t fetch the spec.
Collaborator
Author
|
FastAPI's |
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
Implements Extract and refresh the FastAPI template into a standalone repository. This is a working CommonGrants API on FastAPI: three opportunity routes plus
/health, backed by the same sample data as the Hono template. Requests and responses are validated withcommon-grants-sdk0.8.1, and FastAPI serves the OpenAPI document at/openapi.jsonwith Swagger UI at/docs. Connecting real data means writing one repository class;PORTING.mdwalks through it.Changes proposed
create_app(repository)builds the app from oneOpportunityRepositoryprotocol. The routes own defaults, envelopes and pagination metadata.response_model. Errors are protocol-shaped 400, 404, 405 and 500.verifyruns checks, tests with coverage, andpip-audit --strict.sdk-rangeupdates the SDK within^0.8.1and runs the tests.PORTING.mdand contribution files follow the Hono section order. The license is CC0-1.0, and the README credits the monorepo origin.Context for reviewers
Judgment calls worth a look:
sortBywithoutsortOrdersorts ascending, as Hono does. The routes subclass the SDK request models to set these defaults, so/docsdocuments them. The SDK accepts anysortOrderstring, so an unknown one falls back to the default order and is reported insortInfo.errors.model_copy(update=...)would otherwise reach the client.PORTING.md§6 wrapswith_custom_fieldsin aclassstatement. The website's plain assignment makes pyright reject every annotation that usesOpportunity. I checked the class form with a two-field extension: tests,make check-types, the typed OpenAPI schemas, and runtime validation all passed.httpx2is a dev dependency on purpose. Starlette 1.7'sTestClient, whichfastapi.testclientre-exports, requires it, and itshttpxfallback is deprecated.make auditauditspip freeze --exclude-editable. The project's own editable install is not on PyPI, and--strictfails on it even with--skip-editable.Verified locally on Python 3.11.16 with Poetry 2.5.1:
make install,make ciandmake auditall pass. The audit found no known vulnerabilities.poetry update common-grants-sdkand thenmake test. Both passed, and 0.8.1 is the newest release in range.fastapi runserved all five routes, and the 404 and 400 cases, as expected.Hosted CI passes both jobs on
9974184.Checker run. I ran
make gen-openapi, thennpx @common-grants/cli@0.4.0 check spec openapi.yaml. It printedSpec is valid and compliant with base specand exited 0. This pass was expected and proves nothing on its own. It is the false pass on Pydantic output described in HHS/simpler-grants-protocol#735. Pydantic writes each optional field as ananyOfwith a{type: null}branch, which covers 44 of the document's 46anyOfnodes, and the checker collapsesanyOfto its first member. Sorted by bucket:oneOfand type arrays, from the same report: not exercised, because the document contains neither.