Skip to content

Output Formats

sparktype can generate type definitions in multiple languages and schema libraries from the same OpenAPI specification.

Supported Formats

FormatLanguageDescription
typescriptTypeScriptNative interfaces and type aliases
zodTypeScriptZod schema definitions for runtime validation
pythonPythonTypedDict classes with type hints
goGoStruct definitions with JSON tags

Choosing a Format

TypeScript

Best for:

  • Frontend applications using TypeScript
  • Type-only imports (no runtime overhead)
  • Maximum IDE support
jsonc
{
  "format": "typescript",
  "options": {
    "exportType": "interface"
  }
}

Zod

Best for:

  • Runtime validation of API responses
  • Form validation
  • Data parsing with transformations
jsonc
{
  "format": "zod",
  "options": {
    "inferTypes": true
  }
}

Python

Best for:

  • FastAPI or Flask backends
  • Type checking with mypy/pyright
  • Python 3.10+ projects
jsonc
{
  "format": "python"
}

Go

Best for:

  • Go microservices
  • API clients in Go
  • Backend services
jsonc
{
  "format": "go",
  "options": {
    "package": "types"
  }
}

Multiple Formats

Generate multiple formats from the same spec:

jsonc
{
  "specs": {
    "api": { "path": "./openapi.yaml" }
  },
  "outputs": [
    {
      "path": "./frontend/src/types/api.ts",
      "format": "typescript",
      "contents": ["api:*"]
    },
    {
      "path": "./frontend/src/schemas/api.ts",
      "format": "zod",
      "contents": ["api:*"],
      "options": { "inferTypes": true }
    },
    {
      "path": "./backend/types/api.py",
      "format": "python",
      "contents": ["api:*"]
    },
    {
      "path": "./services/types/api.go",
      "format": "go",
      "contents": ["api:*"],
      "options": { "package": "types" }
    }
  ]
}

Global Options

These options affect all formats:

OptionEffect
generateEnumsUse native enums vs union types
nullableHandlingHow nullable fields are represented
dereferenceRefsInline references vs named types

See Options for details.

Generated File Header

All generated files include a header comment:

// Generated by an automated build step. Do not edit.

Or in Python:

python
# Generated by an automated build step. Do not edit.

This helps identify generated files and prevents accidental manual edits.

Next Steps

  • TypeScript - Interface and type generation
  • Zod - Schema generation with runtime validation
  • Python - TypedDict generation
  • Go - Struct generation

Released under the MIT License.