feat: introduce BetterGov.ph Project Registry with schema validation, GET API, and test suite#635
Conversation
|
In relation to #634 |
jasontorres
left a comment
There was a problem hiding this comment.
I'm okay with this approach so far. Although I didn't really want an API because it just creates an overhead. A static file served in public/api/projects.json would have been easier?
|
Yeah I might have over-engineered this. I was thinking that, in sites that had the Just had a stroke of productivity when making this, we can let the callers handle API-fication on their end. Will revise to a static |
|
No thank you. I appreciate it. Please keep this branch somewhere as we might need it in the future. Then update this existing with the simplified. We'll come back to the proper /api routes/workers as there's some big changes I'm planning for BetterGov. I hope for your participation when that time comes! |
|
Got this! Will create a separate pull request |
|
Archived API implementation into #637. This now contains a static |
Note
The original version of this PR included a full Cloudflare Worker API (
GET /api/projects) with filtering, pagination, search, and a 53-test suite. Per maintainer feedback, this has been simplified to a static JSON file served as a public asset. The full API implementation is archived in #637 and will be revisited when the broader project has been revealed and is ready.Summary
Introduces a centralized, JSON-based Project Registry (
public/api/projects.json) as the single source of truth for all officially recognized BetterGov.ph projects, with pre-commit schema validation to guard data integrity.Motivation
As BetterGov.ph grows into an ecosystem of projects — not all of which live within the
bettergovphGitHub organization — there was no single source of truth for which projects are officially recognized. This registry solves that by:/api/projects.json)Changes
1. Project Registry —
public/api/projects.jsonA new JSON file seeded with all 16 currently recognized BetterGov.ph projects, sourced from the existing
ourProjectslist innavigation.tsand enriched with descriptions and repository URLs fetched from thebettergovphGitHub org.Each entry contains:
slugtitledescriptionrepositoryUrlsprojectUrlstatusactive|development|archived2. JSON Schema —
src/data/schema/projects.schema.jsonA JSON Schema Draft-07 file enforcing the registry structure:
additionalProperties: falseslugvalidated as kebab-case via regex (^[a-z0-9]+(?:-[a-z0-9]+)*$)projectUrland eachrepositoryUrlvalidated as HTTPS URLsstatusvalidated as an enum3. Pre-commit Validation —
.lintstagedrc.jsSchema validation is wired into the existing husky → lint-staged pre-commit pipeline. Whenever
public/api/projects.jsonis staged, the commit is blocked if any entry violates the schema.This also fixes a pre-existing bug in
validate-json-schema.jswhere Ajv v8's strict mode caused any schema usingformatkeywords (including the existingservices.schema.jsonandpopulation-2020.schema.json) to fail to compile. Fixed by passingstrict: falseto the Ajv instance.Files changed
public/api/projects.jsonsrc/data/schema/projects.schema.json.lintstagedrc.jsprojects.jsonscripts/validate-json-schema.jsstrict: falseon Ajv to supportformatkeywords in existing schemasArchived work
The full API implementation (Cloudflare Worker endpoint, 53-test suite, vitest setup,
wrangler.test.jsonc) is preserved in #637 for future reference.