Generate TypeScript, Python, and Go types from JSON Schema (JSON and YAML). One binary, zero dependencies.
brew tap mirpo/homebrew-tools
brew install schemagengo install github.com/mirpo/schemagen@latestDownload from GitHub Releases.
# Generate TypeScript
schemagen generate schemas/ --out-ts ./types
# Generate Python (Pydantic v2)
schemagen generate schemas/ --out-py ./models
# Generate Go
schemagen generate schemas/ --out-go ./models
# All three at once
schemagen generate schemas/ --out-ts ./types --out-py ./models --out-go ./models
# YAML schemas work too
schemagen generate schemas/*.yaml --out-ts ./typesThese flags are available for all commands:
-v, --verbose- Enable verbose/debug logging--json- Output logs in JSON format
Generate code from JSON Schema files. Input can be a .json, .yaml, or .yml file, a directory, or a glob pattern.
schemagen generate <input> [flags]Flags:
Output directories:
--out-ts <dir>- TypeScript output directory--out-py <dir>- Python output directory--out-go <dir>- Go output directory
General:
--extract-inline- Extract inline enums and nested objects to top-level types--output-strategy <strategy>- Output strategy:bundle,multifile, orbundledeps(default:multifile)--disable-headers- Remove generated file headers--disable-timestamp- Remove timestamp from headers
TypeScript-specific:
--ts-unknown-any- Useunknowninstead ofanyfor untyped schemas--ts-additional-properties- Add index signatures for additionalProperties
Python-specific:
--py-snake-case-field- Convert field names to snake_case with JSON alias--py-additional-properties- Addmodel_config = ConfigDict(extra='allow')for schemas with additionalProperties
Go-specific:
--go-package <name>- Package name for generated files (default:models)--go-pointers- Use pointers for optional fields (default:true)--go-omit-empty- Add omitempty to optional JSON tags (default:true)--go-module-path <path>- Go module path for absolute imports (e.g.,github.com/org/project)
Check if schemas are valid JSON Schema.
schemagen validate schemas/Flags:
--format <format>- Output format:textorjson(default:text)
Check if generated code matches schemas. Returns exit code 2 if drift detected. Useful for CI.
schemagen verify schemas/ --out-ts ./typesFlags:
--quiet- Suppress output (only exit codes)
Show what would change if you regenerated.
schemagen diff schemas/ --out-ts ./typesFlags:
--no-color- Disable colored diff output
- Objects → structs / interfaces / BaseModel classes
- Enums → string/int/mixed enums (string unions in TS,
Enum/IntEnumin Python, typed constants in Go) - Primitives → native types with format handling (uuid, email, date-time, etc.)
- Arrays / Maps → typed slices/arrays/dicts
- allOf → struct embedding (Go), class inheritance (Python),
.extend()(TS/Zod) - anyOf / oneOf → union types (
Type1 | Type2in TS,Union[Type1, Type2]in Python,anyin Go) - $ref → cross-file references with automatic import generation
JSON Schema validation constraints are propagated to generated code:
| Constraint | TypeScript (Zod) | Python (Pydantic) | Go (validator tags) |
|---|---|---|---|
minLength / maxLength |
.min() / .max() |
min_length / max_length |
min / max |
pattern |
.regex() |
pattern |
— |
minimum / maximum |
.gte() / .lte() |
ge / le |
gte / lte |
exclusiveMinimum / exclusiveMaximum |
.gt() / .lt() |
gt / lt |
gt / lt |
multipleOf |
.multipleOf() |
multiple_of |
— |
minItems / maxItems |
.min() / .max() |
min_length / max_length |
min / max |
- JSON Schema (
.json) - YAML Schema (
.yaml,.yml)
- Interfaces with JSDoc comments and
@formatannotations - Union types for anyOf/oneOf, string literal unions for string enums
- Auto-generated barrel exports (
index.ts)
- Pydantic v2 BaseModel classes with full constraint validation
- Format types (EmailStr, UUID, datetime)
- Enum classes (
str, Enum/IntEnum/Literalfor mixed) - Optional:
model_config = ConfigDict(extra='allow')for additionalProperties (use--py-additional-properties) - Auto-generated barrel exports (
__init__.py)
- Structs with JSON tags and go-playground/validator tags
- Embedded structs for allOf composition
- UUID and time.Time format types
- Configurable pointer usage and package naming
Generate Zod schemas alongside TypeScript interfaces:
# Interfaces + Zod schemas
schemagen generate schema.json --out-ts ./types --ts-zod
# Only Zod schemas (with z.infer<> types)
schemagen generate schema.json --out-ts ./types --ts-zod-only
# Additional options
--ts-zod-strict # Add .strict() to object schemas
--ts-zod-coerce-dates # Use z.coerce.date() for date-timePython output uses Pydantic v2 BaseModel with built-in validation:
- Field constraints:
min_length,max_length,pattern,ge,le,gt,lt,multiple_of - Format types:
EmailStr,UUID,datetime - Enums with string/int values
MIT