Skip to content

feat: add auto-generated Zod schemas and drift detection#124

Merged
benminer merged 14 commits intomainfrom
feature/v2-buyer-zod-schemas
Mar 19, 2026
Merged

feat: add auto-generated Zod schemas and drift detection#124
benminer merged 14 commits intomainfrom
feature/v2-buyer-zod-schemas

Conversation

@benminer
Copy link
Collaborator

@benminer benminer commented Mar 17, 2026

Adds auto-generated Zod schemas from OpenAPI specs with drift detection and automatic schema regeneration.

Changes:

  • Integrate openapi-zod-client to generate Zod schemas from the v2 Buyer API OpenAPI spec
  • Implement API drift detection that identifies schema changes and triggers automated PR creation
  • Add npm scripts (generate-schemas, detect-drift) and GitHub workflows (regenerate-schemas, drift-detection)
  • Include Slack notifications for drift alerts and schema regeneration PRs
  • Update workflow configurations and add Node.js version specification
  • Include schemas in distributed package with full IntelliSense support (import { buyer } from 'scope3')
  • Strip Zodios client code from generated output (only pure Zod schemas are distributed)

Resolves the need for manual type maintenance by automating schema generation based on live API specs.

Next Steps

The generated schemas are exported but not yet used internally by the SDK. A follow-up PR should:

  1. Replace hand-written types with schema-derived types — Use z.infer<typeof schema> in src/types/ so schemas become the single source of truth instead of maintaining duplicate interfaces
  2. Validate API responses at runtime — Parse responses through Zod schemas in the adapter layer (RestAdapter/McpAdapter) to catch API contract mismatches early
  3. Validate inputs before requests — Use schemas to validate create/update inputs in resource classes, giving consumers clear validation errors before requests are sent

- Add openapi-zod-client integration to generate Zod schemas from OpenAPI specs
- Implement drift detection to identify API changes and trigger schema regeneration
- Add npm scripts: generate-schemas and detect-drift
- Create workflows: regenerate-schemas.yml and drift-detection.yml
- Add Slack notifications for drift alerts and schema regeneration PRs

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@benminer benminer requested a review from a team March 17, 2026 15:14
benminer and others added 7 commits March 17, 2026 10:30
The scope3data/actions/node/install composite action is not resolvable
in PR CI context. Revert to the original setup-node + npm ci approach.
- Add /* eslint-disable */ header to generated buyer.ts to suppress
  lint errors on auto-generated code
- Fix unnecessary \& escape characters in generated output
- Update generate-schemas.ts post-processing to apply both fixes
- Add changeset for the zod schemas feature

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Strip @zodios/core dependency and @ts-nocheck from generated schemas
- Remove tsconfig exclusion so schemas compile to dist/
- Export schemas from package entry point (src/index.ts)
- Consumers can now import { buyer } from 'scope3' for full IntelliSense

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace external trigger dependency with GitHub Actions cron schedule.
Manual workflow_dispatch is still available for ad-hoc runs.
- Add SLACK_TOKEN env to both drift-detection and regenerate-schemas workflows
- Replace actions/github-script dispatch with workflow_call (reusable workflow)
  since GITHUB_TOKEN cannot trigger workflow_dispatch on other workflows
- Add job output to pass drift_detected flag between jobs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
benminer and others added 4 commits March 18, 2026 12:46
Consumers who need z can import it directly from zod.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the hardcoded SDK_METHODS inventory with three automated sources:

- OpenAPI spec: fetched from staging and parsed for all path/method pairs
- skill.md: already fetched via existing fetcher (unchanged)
- SDK code: extracted by scanning src/resources/*.ts for adapter.request() calls

The report now shows a three-way comparison with the OpenAPI spec as
source of truth, highlighting where skill.md and SDK each diverge.

Also updates the GitHub workflow's Slack message to show the new
drift categories.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add post-processing to normalize snake_case schema names to PascalCase
- Remove duplicate aliases that collapse to the same name after rename
- Check for existing open regeneration PRs before creating a new one
- Remove z re-export from generated index.ts
Copy link
Collaborator

@nastassiafulconis nastassiafulconis left a comment

Choose a reason for hiding this comment

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

solid first pass! the automated drift detection + regeneration loop is a nice pattern. main thing to fix before this ships is the staging vs prod URL mismatch in detect-drift.ts — everything else is non-blocking. the naming inconsistencies in buyer.ts and the Error shadowing are worth cleaning up in a follow-on.

@benminer benminer merged commit 439633e into main Mar 19, 2026
6 checks passed
@benminer benminer deleted the feature/v2-buyer-zod-schemas branch March 19, 2026 22:09
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