Improve API response reuse and content validation#390
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
et3 | bf76c65 | Commit Preview URL Branch Preview URL |
Jan 13 2026, 08:22 PM |
Summary of ChangesHello @zz-plant, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the API response generation and content validation mechanisms. By centralizing common response logic into a new utility file, it streamlines API route handlers and promotes consistency across all API endpoints. Additionally, it enhances content validation by dynamically discovering all content JSON files and introducing robust Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant improvement to the codebase. The centralization of API response logic into src/utils/api-responses.ts drastically reduces code duplication in the API route handlers, making them much cleaner and easier to maintain. The move to dynamic content file discovery in validate-json.ts using Bun.Glob is a great step towards a more robust validation process. Furthermore, introducing zod for schema validation in validate-glossary.ts is an excellent choice that enhances type safety and provides clear, structured error messages. Overall, these are high-quality changes that improve maintainability, robustness, and developer experience. I have a couple of suggestions for further refinement, but the core changes are solid.
| const core = [ | ||
| "site-index.json", | ||
| "standards.json", | ||
| "clauses.json", | ||
| "mechanisms.json", | ||
| "validators.json", | ||
| "glossary.json", | ||
| "anti-patterns.json", | ||
| "evidence-packs.json", | ||
| "findings.json", | ||
| "diagnostic-results.json", | ||
| "rag-corpus.jsonl", | ||
| ]; |
There was a problem hiding this comment.
The core array of endpoints is hardcoded. While centralizing this list is an improvement, it still requires manual updates when new API endpoints are added, which can be error-prone. For future maintainability, consider exploring ways to generate this list dynamically from your API routes, if your framework supports it. This would make the site index more robust to changes.
| const standards = getStandardsForApi().map((standard) => ({ | ||
| id: standard.id, | ||
| title: standard.title, | ||
| status: standard.status, | ||
| version: standard.version, | ||
| effectiveDate: standard.effectiveDate, | ||
| published: standard.published, | ||
| href: standard.href, | ||
| type: standard.type, | ||
| refs: standard.refs, | ||
| })); | ||
|
|
||
| const validators = getValidatorsForApi().map((validator) => ({ | ||
| id: validator.id, | ||
| title: validator.title, | ||
| description: validator.description, | ||
| standardRef: validator.standardRef, | ||
| href: validator.href, | ||
| type: validator.type, | ||
| refs: validator.refs, | ||
| })); | ||
|
|
||
| const publications = researchContent.publications.map((publication) => ({ | ||
| title: publication.title, | ||
| type: publication.type, | ||
| summary: publication.summary, | ||
| tags: publication.tags, | ||
| href: publication.href, | ||
| })); |
There was a problem hiding this comment.
The createSiteIndexResponse function currently includes data transformation logic (the .map calls for standards, validators, and publications). To improve separation of concerns, consider moving this data-shaping logic to src/utils/api.ts. For example, you could create functions like getStandardsForSiteIndex() in api.ts that return the data in the shape needed for the site index. This would leave api-responses.ts focused purely on building HTTP Response objects, making the code more modular and easier to reason about.
Motivation
Description
src/utils/api-responses.tswith shared response builders (createSiteIndexResponse,createStandardsResponse,createClausesResponse,createRagCorpusResponse) and helpers for JSON/NDJSON responses./apiand/api/v/2026.01) to delegate to the new builders (e.g.site-index.json.ts,standards.json.ts,clauses.json.ts,rag-corpus.jsonl.ts).validate-json.tsto useBun.Globand scansrc/content/*.json, sort the files, and fail fast when none are found.zodschema validation tovalidate-glossary.tsfor glossary and library content and switch error output to use.error.issuesfor clearer, structured messages.Testing
bun run check(which executes lint, unit tests, typecheck,astro check,validate:json, andvalidate:glossary) and it completed successfully while reporting existing TypeScript deprecation warnings and Astro hints.bun test(17 tests across 7 files) with14 pass,3 skip, and0 fail.bun run validate-json.tswhich scanned and validated allsrc/content/*.jsonfiles successfully.bun run validate-glossary.tsand it completed with✅ Glossary validation passed.Codex Task