Help us shape the future of Go! Take the 2026 Go Developer Survey

typescript

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package typescript generates a typed TypeScript client SDK from an AuthSome OpenAPI spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldDef

type FieldDef struct {
	Name     string
	Type     string
	Optional bool
}

FieldDef represents a field in a TypeScript interface.

type GeneratedFile

type GeneratedFile struct {
	Path    string
	Content string
}

GeneratedFile represents a single generated file.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator produces TypeScript SDK code from an OpenAPI spec.

func NewGenerator

func NewGenerator(cfg GeneratorConfig) *Generator

NewGenerator creates a TypeScript SDK generator.

func (*Generator) Generate

func (g *Generator) Generate(spec *openapi.Spec) ([]GeneratedFile, error)

Generate produces all TypeScript SDK files from the given spec.

type GeneratorConfig

type GeneratorConfig struct {
	// PackageName is the npm package name (default: "@authsome/client").
	PackageName string

	// PackageVersion is the npm package version (default: "0.5.0").
	PackageVersion string

	// OutputMode controls what files are generated.
	// "standalone" (default) — full npm package (types, client, index, package.json, tsconfig).
	// "embedded" — only api-types.ts and api-client.ts for embedding in another package.
	OutputMode string

	// MethodOverrides maps operationID to a custom method name.
	// e.g., {"refreshSession": "refresh", "deleteAccount": "deleteMe"}
	MethodOverrides map[string]string
}

GeneratorConfig configures the TypeScript SDK generator.

type OperationDef

type OperationDef struct {
	Name              string
	Method            string
	Path              string
	Summary           string
	HasBody           bool
	FormBody          bool
	BodyType          string
	ResponseType      string
	AuthRequired      bool
	Tags              []string
	PathParams        []PathParamDef
	QueryParams       []QueryParamDef
	NeedsRequestAlias bool // true when the request type alias differs from an existing schema type
}

OperationDef represents a generated client method.

type PathParamDef

type PathParamDef struct {
	Name   string // Original name from the spec (e.g., "orgId")
	TSName string // TypeScript parameter name (e.g., "orgId")
}

PathParamDef represents a path parameter in an operation.

type QueryParamDef

type QueryParamDef struct {
	Name     string // Original name from the spec (e.g., "limit")
	TSName   string // TypeScript parameter name (e.g., "limit")
	Type     string // TypeScript type (e.g., "number", "string[]")
	Required bool

	// Repeated marks an array-typed query parameter, which is sent once per
	// value rather than once in total. Query parameters default to style form
	// with explode true, so an array in the document means exactly that.
	Repeated bool
}

QueryParamDef represents a query parameter in an operation.

type TemplateData

type TemplateData struct {
	PackageName        string
	PackageVersion     string
	OutputMode         string
	Types              []TypeDef
	Operations         []OperationDef
	RequestTypeImports []string // Additional request type names to import (not already in Types)
	HasSocial          bool
	HasMagicLink       bool
	HasMFA             bool
}

TemplateData holds all data passed to templates.

type TypeDef

type TypeDef struct {
	Name       string
	Fields     []FieldDef
	IsResponse bool
}

TypeDef represents a generated TypeScript interface.

Jump to

Keyboard shortcuts

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