gotypegen

module
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: MIT

README

gotypegen

Generate TypeScript, Python, JSON Schema, and Go types from Go source code.

Originally based on tygo by Guido Zuidhof (MIT). Extended with Python TypedDict/Enum output, JSON Schema output, Go source output with method tracing, and dependency tracing.

Install

go install github.com/inference-sh/gotypegen/cmd/gotypegen@latest

Usage

gotypegen [--format=typescript,jsonschema,python,go] [config.yaml]
Config
packages:
  - path: "your/go/package"
    output_path: "gen/types.ts"
    type_mappings:
      time.Time: "string /* RFC3339 */"
      uuid.UUID: "string /* uuid */"
Formats
  • typescript (default) — TypeScript interfaces and const exports
  • python — Python TypedDict classes and StrEnum/IntEnum
  • jsonschema — JSON Schema 2020-12 definitions
  • go — Go source with methods, tag stripping, and go.mod generation
Dependency Tracing

Only emit types reachable from specific entry files:

packages:
  - path: "your/go/package"
    output_path: "gen/sdk.ts"
    mode: "trace"
    entry_files:
      - api.go
Go Output

Generate standalone Go packages from traced types, including methods and struct tag filtering:

packages:
  - path: "your/go/package"
    output_path: "gen/sdk.go"
    mode: "trace"
    entry_files:
      - api.go
    go_package: "sdk"
    go_module: "github.com/you/sdk-go"
    keep_tags:
      - json
      - yaml
  • go_package — package name for generated code (default: types)
  • go_module — if set, also generates a go.mod
  • keep_tags — allowlist of struct tags to keep (strips all others, e.g. gorm, validate)
  • Methods on traced types are included if they only reference stdlib and other traced types
Directives

Use //gotypegen:emit to inject raw output:

//gotypegen:emit export type CustomType = string | number;
var _ = ""

License

MIT — see LICENSE and THIRD_PARTY.

Directories

Path Synopsis
cmd
gotypegen command
gotypegen generates TypeScript, JSON Schema, Python, and Go types from Go source code.
gotypegen generates TypeScript, JSON Schema, Python, and Go types from Go source code.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL