Documentation
¶
Overview ¶
Package codegen orchestrates AsyncAPI → Go generation.
Pipeline:
- Load the AsyncAPI spec.
- Resolve every message payload's $ref to a JSON Schema file.
- Invoke go-jsonschema in-process to emit payload Go types (cross-tree $refs become Go imports per Config.SchemaPackages).
- Lower the spec to IR; render typed publishers per `action: send` operation.
- Combine, inject imports, gofmt, write one Go file.
Wire-compat (accepting legacy PascalCase JSON alongside the canonical camelCase) is intentionally out of scope: aapi-codegen does not emit UnmarshalJSON shims. Consumers that need it hand-write a small `compat.go` sibling to the generated file and retire it once the legacy publishers are gone — the kind of transitional debt that doesn't belong in generated code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultInitialisms = []string{"ID", "URL"}
DefaultInitialisms is the initialism list applied when Config.Initialisms is empty. Mirrors oapi-codegen's pattern: defaults are baked in; user-supplied entries are additive.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Package string
Output string
// Initialisms supplements DefaultInitialisms when configuring
// go-jsonschema's --capitalization rules. Empty means defaults only.
Initialisms []string
// SchemaPackages drives cross-tree $ref → import behaviour. For each
// entry, go-jsonschema emits `import alias "package"` at the use
// site instead of inlining the schema's types.
SchemaPackages []SchemaPackageMapping
// OmitValidation suppresses go-jsonschema's generated UnmarshalJSON
// methods (required-field checks, strict additionalProperties,
// format/enum/numeric-bound validators, etc.). False (the default)
// means validation is included; true is the opt-out for consumers
// that hand-write their own UnmarshalJSON, e.g. for wire-compat
// (camelCase ↔ legacy PascalCase): two UnmarshalJSON methods on the
// same type would be a compile error, so wire-compat consumers must
// opt out here to define their own.
OmitValidation bool
}
Config is the internal codegen surface. The user-facing YAML Configuration translates into this via Configuration.ToCodegenConfig.
type Configuration ¶
type Configuration struct {
Package string `yaml:"package"`
Output string `yaml:"output"`
SchemaPackages []SchemaPackageMapping `yaml:"schema-packages"`
// Capitalization mirrors go-jsonschema's --capitalization flag list.
// When empty, DefaultInitialisms is applied.
Capitalization []string `yaml:"capitalization"`
// OmitValidation opts out of go-jsonschema's generated UnmarshalJSON
// methods. Default false (validation included). Set true only when
// consumers will hand-write their own UnmarshalJSON (e.g. for the
// camelCase ↔ legacy PascalCase wire-compat pattern); a generated
// UnmarshalJSON and a hand-written one on the same type is a
// compile error.
OmitValidation bool `yaml:"omit-validation"`
}
Configuration is the YAML-driven config aapi-codegen reads via the CLI's -config flag. Mirrors oapi-codegen's pattern: top-level package + output, plus an aapi-codegen-specific schema-packages block that absorbs the cross-tree $ref mapping today's per-schema-dir generate.sh files express as repeated --schema-package CLI args. See plan §6.
Fields not set in YAML default to zero; CLI flags supersede YAML values when both are present (the precedence is established by MergeFlags).
func LoadConfiguration ¶
func LoadConfiguration(path string) (*Configuration, error)
LoadConfiguration parses a YAML config file. Returns an error rather than silently filling in defaults — a typo in the YAML key should surface, not be papered over.
func (*Configuration) MergeFlags ¶
func (c *Configuration) MergeFlags(pkg, output string, capitalization []string)
MergeFlags overlays CLI-flag values onto a config loaded from YAML. A non-empty flag value wins; this lets the CLI run a config file as the base while still supporting one-off overrides without editing YAML.
func (*Configuration) ToCodegenConfig ¶
func (c *Configuration) ToCodegenConfig() Config
ToCodegenConfig translates a Configuration into the codegen.Config the internal pipeline consumes. Kept as a translation step so the YAML schema can evolve independently of the internal struct's fields.
type SchemaPackageMapping ¶
type SchemaPackageMapping struct {
ID string `yaml:"id"`
Package string `yaml:"package"`
Alias string `yaml:"alias"`
}
SchemaPackageMapping ties a JSON-Schema $id to the Go package its types live in. Aliasing is mandatory because two canonical schemas commonly share a last path segment (`v1`/`v1`) and Go's import-alias derivation would otherwise collide.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ir is the binding-agnostic intermediate representation that sits between the AsyncAPI loader and the Go-source templates.
|
Package ir is the binding-agnostic intermediate representation that sits between the AsyncAPI loader and the Go-source templates. |
|
Package loader parses an AsyncAPI 3.x YAML document into a typed in-memory representation.
|
Package loader parses an AsyncAPI 3.x YAML document into a typed in-memory representation. |
|
Package lower turns a parsed AsyncAPI document (loader.Document) into the binding-agnostic IR (ir.Spec) the publisher template iterates over.
|
Package lower turns a parsed AsyncAPI document (loader.Document) into the binding-agnostic IR (ir.Spec) the publisher template iterates over. |
|
Package schema models the slice of JSON Schema 2020-12 that the compat-shim emitter cares about.
|
Package schema models the slice of JSON Schema 2020-12 that the compat-shim emitter cares about. |