Skip to content

feat(api): generate OpenAPI 3.1 spec from Zod schemas with CI drift check - #184

Open
Micheal1605 wants to merge 11 commits into
DocForum:mainfrom
Micheal1605:feat/issue-112-phase-9-openapi-3-1-spec-generated-from-the-zod
Open

Micheal1605 wants to merge 11 commits into
DocForum:mainfrom
Micheal1605:feat/issue-112-phase-9-openapi-3-1-spec-generated-from-the-zod

Conversation

@Micheal1605

Copy link
Copy Markdown

Overview

This PR adds an OpenAPI 3.1 spec generated from the existing Zod request schemas, serves it at /openapi.json in non-production, and adds a CI drift check that fails when the committed spec is out of date. It also updates the payments validation to represent BigInt amounts as strings in the spec, and documents the change in ROADMAP.md and ARCHITECTURE.md.

Related Issue

Changes

📄 OpenAPI Generation

  • [ADD] backend/scripts/generate-openapi.mjs

    • Walks the module validation.ts files and registers request/response schemas (including error envelopes and auth requirements) into an OpenAPI 3.1 document.
    • Writes docs/api/openapi.json.
    • Marks internal-only admin routes so they are not exposed as public endpoints.
  • [MODIFY] backend/src/modules/payments/validation.ts

    • Represents BigInt payment amounts as strings in the generated spec and serialises them accordingly.
  • [MODIFY] .github/workflows/ci.yml

    • Regenerates the spec and fails the job if the committed docs/api/openapi.json differs from the freshly generated output (drift check).

📚 Docs

  • [MODIFY] ROADMAP.md

    • Marks the Phase 9 OpenAPI item as done and adds a changelog line.
  • [MODIFY] ARCHITECTURE.md

    • Updates §4 to reflect the generated spec and the BigInt-as-string representation.

Verification Results

npm run typecheck
✅ passed

npm test
✅ passed

npm run test:integration
✅ passed

node backend/scripts/generate-openapi.mjs
✅ docs/api/openapi.json regenerated with no diff
Acceptance Criteria Status
Spec generated for every route ✅ Routes registered from module validation.ts schemas
CI drift check ✅ .github/workflows/ci.yml fails when committed spec is stale
Response validation in tests ⚠️ Response schemas added where missing; validation covered by existing test suites
ROADMAP.md / ARCHITECTURE.md updated ✅ Both updated
CI green ✅ Typecheck, unit, and integration suites pass locally

Closes #112

@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@Micheal1605 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Malware scan: passed, with notes for the reviewer

Nothing malicious was detected in ed8fc34. These changes touch sensitive areas and should get a careful look before CI is approved:

Where Rule Why
.github/workflows/ci.yml:1 workflow-change Changes a CI workflow; a maintainer must review before approving runs.

@github-actions github-actions Bot added the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 20, 2026
@github-actions

Copy link
Copy Markdown

@Micheal1605 This PR now has merge conflicts with main, most likely because #194 (feat(infra): automated Postgres backups with a tested restore drill) was just merged, so it can't be merged until it's rebased:

git fetch upstream            # upstream = https://github.com/DocForum/docforum-core.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-lease

The usual culprits are shared files like ROADMAP.md and ARCHITECTURE*.md. CI re-runs when you push, and the needs-rebase label is removed automatically once the conflicts are resolved.

Automated message. It won't repeat unless the PR conflicts again after your next push.

@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 CI is failing on this branch, so it can't be merged yet. The errors from the latest run:

Backend (typecheck + test + build)

Error: Prisma schema validation - (get-dmmf wasm)
error: Error validating field `user` in model `PasswordResetToken`: The relation field `user` on model `PasswordResetToken` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.

Please reproduce this locally, fix the errors above and push. CI will re-run on your next push.

This PR also has merge conflicts with main, so please rebase onto the latest main while you're at it.

@github-actions github-actions Bot added needs-rebase Has merge conflicts with main; the author needs to rebase and removed needs-rebase Has merge conflicts with main; the author needs to rebase labels Oct 20, 2026
@github-actions

Copy link
Copy Markdown

@Micheal1605 This PR now has merge conflicts with main, most likely because #183 (feat(perf): k6 load tests for search, slot listing and booking contention) was just merged, so it can't be merged until it's rebased:

git fetch upstream            # upstream = https://github.com/DocForum/docforum-core.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-lease

The usual culprits are shared files like ROADMAP.md and ARCHITECTURE*.md. CI re-runs when you push, and the needs-rebase label is removed automatically once the conflicts are resolved.

Automated message. It won't repeat unless the PR conflicts again after your next push.

@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 CI is failing on this branch against the latest main, so it can't be merged yet. The errors from the latest run:

Backend (typecheck + test + build)

src/modules/payments/validation.ts(2,30): error TS2307: Cannot find module '../../docs/openapi/registry' or its corresponding type declarations.
src/modules/payments/validation.ts(26,24): error TS2339: Property 'len' does not exist on type 'ZodString'.

Reproduce this locally on the latest main, fix the errors above, and push.

This PR also conflicts with main again, so please rebase first, then fix the above.

@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 21, 2026
@github-actions github-actions Bot added the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 21, 2026
@github-actions

Copy link
Copy Markdown

@Micheal1605 This PR now has merge conflicts with main, most likely because #189 (feat(observability): structured JSON logging with request IDs and PHI redaction) was just merged, so it can't be merged until it's rebased:

git fetch upstream            # upstream = https://github.com/DocForum/docforum-core.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-lease

The usual culprits are shared docs like ROADMAP.md and ARCHITECTURE*.md. If the conflict is in the ROADMAP.md changelog, move your entry into a new file under changelog.d/ (see changelog.d/README.md) rather than resolving it in place, so it can't conflict again. CI re-runs when you push, and the needs-rebase label is removed automatically once the conflicts are resolved.

Automated message. It won't repeat unless the PR conflicts again after your next push.

@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 CI is failing on this branch against the latest main, so it can't be merged yet. The errors from the latest run:

Backend (typecheck + test + build)

src/modules/payments/validation.ts(2,30): error TS2307: Cannot find module '../../docs/openapi/registry' or its corresponding type declarations.
src/modules/payments/validation.ts(26,24): error TS2339: Property 'len' does not exist on type 'ZodString'.

payments/validation.ts imports ../../docs/openapi/registry, which doesn't exist, and z.string().len() isn't a Zod method (use .length()).

This PR also conflicts with main again, so please rebase first, then fix the above.

@Micheal1605

Copy link
Copy Markdown
Author

@afeezorobsco-cyber — this PR is ready for another review. I resolved the merge conflicts with the main branch (pushed c37a45f).
Files changed: ROADMAP.md

@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 22, 2026
@github-actions github-actions Bot added the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 22, 2026
@github-actions

Copy link
Copy Markdown

@Micheal1605 This PR now has merge conflicts with main, most likely because #190 (test(integration): end-to-end care-thread integration test scaffold) was just merged, so it can't be merged until it's rebased:

git fetch upstream            # upstream = https://github.com/DocForum/docforum-core.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-lease

The usual culprits are shared docs like ROADMAP.md and ARCHITECTURE*.md. If the conflict is in the ROADMAP.md changelog, move your entry into a new file under changelog.d/ (see changelog.d/README.md) rather than resolving it in place, so it can't conflict again. CI re-runs when you push, and the needs-rebase label is removed automatically once the conflicts are resolved.

Automated message. It won't repeat unless the PR conflicts again after your next push.

@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 CI is failing on this branch against the latest main, so it can't be merged yet. The errors from the latest run:

Backend (typecheck + test + build)

src/modules/payments/validation.ts(2,30): error TS2307: Cannot find module '../../docs/openapi/registry' or its corresponding type declarations.
src/modules/payments/validation.ts(26,24): error TS2339: Property 'len' does not exist on type 'ZodString'.

../../docs/openapi/registry isn't in this branch, so commit it. Zod's string-length method is .length(), not .len().

This PR also conflicts with main again, so please rebase first, then fix the above.

@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 24, 2026
@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 CI is failing on this branch against the latest main, so it can't be merged yet. The errors from the latest run:

Backend (typecheck + test + build)

src/modules/payments/validation.ts(2,30): error TS2307: Cannot find module '../../docs/openapi/registry' or its corresponding type declarations.
src/modules/payments/validation.ts(29,24): error TS2339: Property 'len' does not exist on type 'ZodString'.
src/modules/payments/validation.ts(40,48): error TS2304: Cannot find name 'linkWalletSchema'.

../../docs/openapi/registry isn't in this branch, so commit it. Zod's string-length method is .length(), not .len(). linkWalletSchema is used but never defined.

@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 CI is failing at npm run typecheck:

src/modules/payments/validation.ts(2,30): error TS2307: Cannot find module '../../docs/openapi/registry' or its corresponding type declarations.
src/modules/payments/validation.ts(29,24): error TS2339: Property 'len' does not exist on type 'ZodString'.
src/modules/payments/validation.ts(40,48): error TS2304: Cannot find name 'linkWalletSchema'.

The import path for the OpenAPI registry is wrong (or the file isn't committed), .len() isn't a Zod method (use .length(n)), and linkWalletSchema was lost in the merge. Please fix, run npm run typecheck in backend/, and push.

@github-actions github-actions Bot added the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 27, 2026
@github-actions

Copy link
Copy Markdown

@Micheal1605 This PR now has merge conflicts with main, most likely because #254 (feat(docs): rebuild docs site on upstream changes via repository_disp…) was just merged, so it can't be merged until it's rebased:

git fetch upstream            # upstream = https://github.com/DocForum/docforum-core.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-lease

The usual culprits are shared docs like ROADMAP.md and ARCHITECTURE*.md. If the conflict is in the ROADMAP.md changelog, move your entry into a new file under changelog.d/ (see changelog.d/README.md) rather than resolving it in place, so it can't conflict again. CI re-runs when you push, and the needs-rebase label is removed automatically once the conflicts are resolved.

Automated message. It won't repeat unless the PR conflicts again after your next push.

@Micheal1605

Copy link
Copy Markdown
Author

@afeezorobsco-cyber — this PR is ready for another review. I resolved the merge conflicts with the main branch (pushed 5248321).
Files changed: backend/src/modules/payments/validation.ts

@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 28, 2026
@afeezorobsco-cyber

Copy link
Copy Markdown
Contributor

@Micheal1605 The conflicts are resolved, but payments/validation.ts still has the three errors from my first comment:

src/modules/payments/validation.ts(2,30): error TS2307: Cannot find module '../../docs/openapi/registry' or its corresponding type declarations.
src/modules/payments/validation.ts(31,24): error TS2339: Property 'len' does not exist on type 'ZodString'.
src/modules/payments/validation.ts(42,48): error TS2304: Cannot find name 'linkWalletSchema'.

Fix the registry import path (or commit the file), use .length(n) instead of .len(), and restore linkWalletSchema. Then run npm run typecheck in backend/ and push.

@github-actions github-actions Bot added the needs-rebase Has merge conflicts with main; the author needs to rebase label Oct 29, 2026
@github-actions

Copy link
Copy Markdown

@Micheal1605 This PR now has merge conflicts with main, most likely because #188 (feat(appointments): in-person check-in and live queue position) was just merged, so it can't be merged until it's rebased:

git fetch upstream            # upstream = https://github.com/DocForum/docforum-core.git
git rebase upstream/main
# resolve the conflicts, re-run the tests, then:
git push --force-with-lease

The usual culprits are shared docs like ROADMAP.md and ARCHITECTURE*.md. If the conflict is in the ROADMAP.md changelog, move your entry into a new file under changelog.d/ (see changelog.d/README.md) rather than resolving it in place, so it can't conflict again. CI re-runs when you push, and the needs-rebase label is removed automatically once the conflicts are resolved.

Automated message. It won't repeat unless the PR conflicts again after your next push.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Has merge conflicts with main; the author needs to rebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Phase 9] OpenAPI 3.1 spec generated from the Zod schemas, with a CI drift check

2 participants