Skip to content

Conversation

@sachin-panayil
Copy link
Collaborator

@sachin-panayil sachin-panayil commented Dec 29, 2025

Problem

The Zod validation schema was manually maintained, requiring us to keep it in sync with the gov-codejson schema. This created drift between our logic and the upstream, and added ongoing maintenance burden whenever the schema changed.

Solution

Replaced the manual schema with an auto-generated one

  • Added src/scripts/generate-schema.ts that fetches the official schema from gov-codejson and converts it to Zod using json-schema-to-zod
  • Outputs formatted TypeScript to src/types/CodeJSONSchema.ts
  • Created tests to make sure that generated schema is valid

Result

Schema validation now stays in sync with the gov-codejson, eliminating drift between codebase and upstream changes. This reduces the maintenance burden when schema updates occur since regenerating the types is now a single command

How to Test

  1. Run the schema generator

    • npx ts-node src/scripts/generate-schema.ts
    • verify the generated schema at src/types/CodeJSONSchema.ts
  2. Run the unit tests

    • npm test
    • check to see if tests pass

@sachin-panayil sachin-panayil self-assigned this Dec 29, 2025
Comment on lines +11 to +27
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium test

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 7 days ago

To fix the problem, add an explicit permissions block that limits the GITHUB_TOKEN to only what this workflow needs. This job only checks out code and runs tests, so it only needs read access to repository contents.

The best targeted fix is to add a permissions section to the test job, directly under runs-on: ubuntu-latest. This keeps the scope local to this job and does not affect any other workflows or jobs. The block should set contents: read, which is the minimal permission required for actions/checkout and read-only operations.

Concretely, in .github/workflows/test.yml, between lines 11 and 13, insert:

    permissions:
      contents: read

No imports or other definitions are required, as this is standard GitHub Actions YAML configuration.

Suggested changeset 1
.github/workflows/test.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -9,6 +9,8 @@
 jobs:
   test:
     runs-on: ubuntu-latest
+    permissions:
+      contents: read
 
     steps:
       - name: Checkout repo
EOF
@@ -9,6 +9,8 @@
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repo
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants