codegen

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(config *Config, specPath string) ([]byte, error)

Generate renders the Go or TypeScript source for the AsyncAPI document at specPath. config must have passed Validate.

func GoName

func GoName(name string) string

GoName turns an arbitrary spec name into an exported Go identifier. "instrument_rates", "instrumentRates" and "instrument-rates" all become "InstrumentRates"; "userId" becomes "UserID".

Types

type Config

type Config struct {
	// Language is go or typescript. Empty means go.
	Language Language `yaml:"language"`
	// Package is the Go package name of the generated file. TypeScript output
	// has no package and ignores it.
	Package string `yaml:"package"`
	// Output is the generated file. Empty means asyncapi.gen.go, or
	// asyncapi.gen.ts for TypeScript.
	Output string `yaml:"output"`
	// Generate picks what to generate. Omitted, everything is generated.
	Generate *GenerateOptions `yaml:"generate"`
	// OutputOptions tunes the generated code.
	//nolint:tagliatelle // config keys are kebab-case by design
	OutputOptions OutputOptions `yaml:"output-options"`
}

Config is the generator configuration file. The spec path comes from the command line, and paths are relative to the directory the generator runs in.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and checks the configuration file at path.

func (*Config) Validate

func (c *Config) Validate() error

Validate fills defaults and checks required settings. Call it after any command-line overrides are applied.

type GenerateOptions

type GenerateOptions struct {
	// Models generates the schema types, codecs and validation.
	Models bool `yaml:"models"`
	// Client generates message decoding, the Handler interface, Dispatch and
	// the Client. It needs Models.
	Client bool `yaml:"client"`
}

GenerateOptions picks the parts of the generated file.

type Language

type Language string

Language is the language of the generated file.

const (
	LanguageGo         Language = "go"
	LanguageTypeScript Language = "typescript"
)

Languages the generator writes.

type OutputOptions

type OutputOptions struct {
	// MessageMatchers tells incoming messages apart when the spec gives no
	// const or discriminator to do it. It maps a message key to JSON pointers
	// (RFC 6901) into the payload and the value each must hold.
	//nolint:tagliatelle // config keys are kebab-case by design
	MessageMatchers map[string]map[string]any `yaml:"message-matchers"`
}

OutputOptions tunes the generated code.

Jump to

Keyboard shortcuts

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