Skip to content

Improve API response reuse and content validation#390

Merged
zz-plant merged 1 commit into
mainfrom
codex/enhance-codebase-robustness-and-maintainability
Jan 13, 2026
Merged

Improve API response reuse and content validation#390
zz-plant merged 1 commit into
mainfrom
codex/enhance-codebase-robustness-and-maintainability

Conversation

@zz-plant

Copy link
Copy Markdown
Owner

Motivation

  • Reduce duplication across API route handlers by centralizing response-building logic.
  • Make content validation more robust by scanning all content JSON files instead of a hard-coded list.
  • Surface structured schema errors early for glossary and library content to prevent downstream issues.
  • Provide consistent JSON/NDJSON response shape and headers for both versioned and unversioned endpoints.

Description

  • Add src/utils/api-responses.ts with shared response builders (createSiteIndexResponse, createStandardsResponse, createClausesResponse, createRagCorpusResponse) and helpers for JSON/NDJSON responses.
  • Update API routes (both /api and /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).
  • Extend validate-json.ts to use Bun.Glob and scan src/content/*.json, sort the files, and fail fast when none are found.
  • Add zod schema validation to validate-glossary.ts for glossary and library content and switch error output to use .error.issues for clearer, structured messages.

Testing

  • Ran bun run check (which executes lint, unit tests, typecheck, astro check, validate:json, and validate:glossary) and it completed successfully while reporting existing TypeScript deprecation warnings and Astro hints.
  • Unit tests: ran bun test (17 tests across 7 files) with 14 pass, 3 skip, and 0 fail.
  • Ran bun run validate-json.ts which scanned and validated all src/content/*.json files successfully.
  • Ran bun run validate-glossary.ts and it completed with ✅ Glossary validation passed.

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jan 13, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 zod schema validation for critical content types, leading to more reliable data and improved error reporting.

Highlights

  • API Response Centralization: Introduced src/utils/api-responses.ts to house shared response-building logic, reducing duplication across API route handlers and promoting consistent response structures.
  • Dynamic Content Validation: Updated validate-json.ts to use Bun.Glob for dynamically scanning all src/content/*.json files, ensuring comprehensive content validation without hardcoded file lists.
  • Structured Schema Validation: Implemented zod schemas in validate-glossary.ts for glossary and library content, providing clearer, structured error messages for early detection of data integrity issues.
  • Consistent API Responses: Ensured uniform JSON/NDJSON response shapes and headers across both versioned and unversioned API endpoints by leveraging the new centralized response builders.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +69 to +81
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",
];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment on lines +94 to +122
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,
}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

@zz-plant zz-plant merged commit 0fcc80e into main Jan 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant