1 SDK Generation
Virgil edited this page 2026-03-11 12:03:21 +00:00

SDK Generation

Module: forge.lthn.ai/core/go-build/pkg/sdk

Overview

Generates typed API client SDKs from OpenAPI specifications. Supports four languages with automatic spec detection and breaking change analysis.

Generator Interface

// In generators/ subpackage
type Generator interface {
    Name() string
    Available() bool
    Install() string
    Generate(ctx, opts Options) error
}

Available Generators

Generator Constructor Tool
TypeScript NewTypeScriptGenerator() openapi-generator-cli
Python NewPythonGenerator() openapi-generator-cli
Go NewGoGenerator() oapi-codegen
PHP NewPHPGenerator() openapi-generator-cli

SDK Configuration

# In .core/release.yaml
sdk:
  spec: openapi.yaml          # Auto-detected if empty
  languages: [typescript, python, go, php]
  output: sdk/
  package:
    name: my-api-client
    version: "{{.Version}}"
  diff:
    enabled: true
    fail_on_breaking: false
  publish:
    repo: myorg/sdks
    path: packages/myapi

Breaking Change Detection

pkg/sdk/diff.go compares OpenAPI specs between versions. pkg/sdk/detect.go auto-discovers spec files (openapi.yaml, swagger.json, etc.).

Registry

generators.NewRegistry() manages available generators. Registry.Register() adds generators, Registry.Get() retrieves by language name.