-
-
Notifications
You must be signed in to change notification settings - Fork 181
RFC: Add Zod and JSON Schema type generators #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kiwicopple
wants to merge
12
commits into
supabase:master
Choose a base branch
from
kiwicopple:claude/add-zod-jsonschema-generator-6hC8j
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
RFC: Add Zod and JSON Schema type generators #1036
kiwicopple
wants to merge
12
commits into
supabase:master
from
kiwicopple:claude/add-zod-jsonschema-generator-6hC8j
+1,526
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Users may connect directly to PostgreSQL (not through PostgREST), so types like timestamp and int8 should map differently depending on the driver. Both generators now support a db_driver_type query parameter with postgrest (default) and direct modes. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
These are general-purpose generators not tied to PostgREST, so direct driver types should be the default. Users going through PostgREST can opt in with db_driver_type=postgrest. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Pull Request Test Coverage Report for Build 21581272491Details
💛 - Coveralls |
…ions Nest all Zod schemas under per-schema namespace objects (matching the TypeScript generator's Database type structure) so that tables with the same name in different schemas (e.g. public.users and auth.users) don't produce conflicting exports. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Documentation for all 6 generators (TypeScript, Go, Swift, Python, Zod, JSON Schema) covering endpoints, query parameters, CLI usage, output structure, type mappings, and features. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Use {language}-{format} naming convention (e.g. typescript-zod) so
generators are grouped by language. This makes it extensible for
future variants like python-pydantic, typescript-io-ts, etc.
Renames: docs, route prefix, template file, CLI command, npm script.
https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
The types work with Supabase client libraries but are not tied to them — they can be used with any TypeScript project. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Show practical examples: validating query results, insert data, API request bodies, and deriving static types with z.infer. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Each doc now has a Usage section right after the intro showing practical code examples: reading/validating rows, inserts, updates, and language-specific patterns (Supabase client, FastAPI, Ajv, etc). https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Change import paths to use conventional project-relative paths (e.g. database/types.ts, database/zod.ts, database/schema.json) instead of vague names like db-schemas or database.types. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Specify target versions explicitly in docs and plan so it's clear what the generators produce. Zod v4 is the current major version (released July 2025). JSON Schema Draft 2020-12 is the current stable specification. https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
avallete
reviewed
Feb 2, 2026
Comment on lines
+106
to
+141
| ## Output structure | ||
|
|
||
| The generator produces a single `Database` type with nested schemas: | ||
|
|
||
| ```ts | ||
| export type Database = { | ||
| public: { | ||
| Tables: { | ||
| users: { | ||
| Row: { | ||
| id: number | ||
| name: string | ||
| email: string | ||
| created_at: string | ||
| } | ||
| Insert: { | ||
| id?: number // optional (has default) | ||
| name: string | ||
| email: string | ||
| created_at?: string | ||
| } | ||
| Update: { | ||
| id?: number | ||
| name?: string | ||
| email?: string | ||
| created_at?: string | ||
| } | ||
| Relationships: [...] | ||
| } | ||
| } | ||
| Views: { ... } | ||
| Functions: { ... } | ||
| Enums: { ... } | ||
| CompositeTypes: { ... } | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note
Might wanna do it another way instead. Split things down into interfaces first, then reference them into the Database type something like:
export interface PublicTablesUsersRow {
....
}
export interface PublicTablesUsersInsert {
...
}
export type Database = {
public: {
Tables: {
Row: PublicTablesUsersRow,
Insert: PublicTablesUsersInsert,
...
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds planning docs and documentation for two new type generators:
/generators/typescript-zod) — Generates Zod runtime validation schemas from the database, producingRow,Insert, andUpdateschemas per table. Lets users validate data at runtime, not just at compile time./generators/jsonschema) — Generates a JSON Schema (Draft 2020-12) document. Language-agnostic, can be used for validation in any language or as input to other code generators.Also adds a
docs/folder with documentation for all 6 generators (TypeScript, Go, Swift, Python, and the two new ones). Each doc includes usage examples, type mappings, and query parameters.What's in this PR
This PR is planning and documentation only — no implementation code yet.
plan.mddocs/typescript.mddocs/go.mddocs/swift.mddocs/python.mddocs/typescript-zod.mddocs/jsonschema.mdKey design decisions
See
plan.mdfor full details.db_driver_typeparameter — Both new generators acceptdirect(default) orpostgrestto handle type differences between direct PG drivers and PostgREST (e.g., timestamps asDatevs strings).{language}-{format}naming — The Zod generator istypescript-zod, not justzod, so generators are grouped by language. Extensible for future variants (python-pydantic,typescript-io-ts, etc).zodthemselves). JSON Schema is plain JSON.GeneratorMetadata— Zero changes to the core introspection layer.