Generate the frontend API client from qh's OpenAPI spec - #8
Merged
Conversation
frontend/src/api/schema.ts was hand-written and verified against the live backend, because qh's /openapi.json emitted empty request/response schemas. With i2mint/qh#9 qh now derives full JSON Schema from the EfService Python type hints, so the frontend's API types can be generated from the spec. - backend/export_openapi.py — exports the backend's OpenAPI document to frontend/src/api/openapi.json (the committed API-contract snapshot). - frontend: openapi-typescript devDependency + `gen:api` script generating src/api/openapi.d.ts from openapi.json. - src/api/schema.ts — was 113 lines of hand-written interfaces; now thin aliases (CorpusInfo, Segment, SearchHit, ExploreResult, CreateCorpusBody, QueryBody, ExploreBody) over the generated types. All 8 consumers untouched. - src/surfaces/SearchSurface.tsx — guard SearchHit.source_id, which the generated types correctly show as nullable (ef's source_id: str | None); the hand-written schema had wrongly declared it always-present. - .gitignore — track frontend/src/api/openapi.json (the API contract). Verified end-to-end: tsc + vite build pass; backend serves the enriched /openapi.json; create -> search -> explore -> list -> delete all work, and a browser create+search round-trip through the UI renders with zero errors. Closes #7
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
frontend/src/api/schema.tswas hand-written and verified against the live backend, becauseqh's/openapi.jsonemitted empty request/response schemas. With i2mint/qh#9,qhnow derives full JSON Schema fromef.service.EfService's Python type hints — so the frontend's API types are now generated from the spec.What changed
backend/export_openapi.py— exports the backend's OpenAPI document tofrontend/src/api/openapi.json, the committed API-contract snapshot.openapi-typescriptdevDependency + agen:apiscript that regeneratessrc/api/openapi.d.tsfromopenapi.json.src/api/schema.ts— was 113 lines of hand-written interfaces; now thin aliases (CorpusInfo,Segment,SearchHit,ExploreResult,CreateCorpusBody,QueryBody,ExploreBody) over the generated types. All 8 consumer files are untouched — the named-alias layer keeps the import surface stable.src/surfaces/SearchSurface.tsx— guardsSearchHit.source_id. The generated types correctly show it as nullable (ef'ssource_id: str | None); the hand-written schema had wrongly declared it always-present, so this is a latent-bug fix the generated types surfaced..gitignore— trackfrontend/src/api/openapi.json(it was caught by a broad*.jsonignore).Refresh workflow
After a backend API change:
Verification
pnpm typecheckandpnpm buildpass./openapi.json(withcomponents.schemas).create_corpus→search→explore_corpus→list_corpora→delete_corpusall work over HTTP.Closes #7
Refs i2mint/qh#9