{"modulePath":"github.com/plheide/aapi-codegen","version":"v0.13.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package codegen\n\nPackage codegen orchestrates AsyncAPI → Go generation.\n\nPipeline:\n\n  - Load the AsyncAPI spec.\n  - Resolve every message payload's $ref to a JSON Schema file.\n  - Invoke go-jsonschema in-process to emit payload Go types (cross-tree $refs become Go imports per Config.SchemaPackages).\n  - Lower the spec to IR; render typed publishers per \\`action: send\\` operation.\n  - Combine, inject imports, gofmt, write one Go file.\n\nWire-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.\n\n## Variables\n\n```go\nvar DefaultInitialisms = []string{\"ID\", \"URL\"}\n```\nDefaultInitialisms is the initialism list applied when Config.Initialisms is empty. Mirrors oapi-codegen's pattern: defaults are baked in; user-supplied entries are additive.\n\n## Functions\n\n```go\nfunc Generate(specPath string, cfg Config) (string, error)\n```\nGenerate runs the pipeline end-to-end and writes one Go file at cfg.Output. Returns the absolute output path on success.\n\n```go\nfunc RenderParameterEnums(spec *ir.Spec) (string, error)\n```\nRenderParameterEnums emits one \\`type \\\u003cT\u003e string\\` + \\`const ( ... )\\` block per channel-parameter enum the spec declared, plus one \\`type \\\u003cT\u003e string\\` + \\`var \\\u003ct\u003ePattern = regexp.MustCompile(...)\\` + \\`New\\\u003cT\u003e\\` + \\`Must\\\u003cT\u003e\\` block per pattern-validated parameter (v0.4.1+).\n\nReturns \"\" when the spec has no parameter types — caller skips emission. The block intentionally precedes the publisher / subscriber sections so generated Send / Subscribe signatures can reference the types without forward declarations.\n\nNaming: GoTypeName comes from the lowerer (pascalized parameter name). Enum constants are \\\u003cTypeName\u003e\\\u003cPascalized(value)\u003e. Pattern types ship a regex var (private, named \\`\\\u003clowercasedType\u003ePattern\\`), a returning constructor (\\`New\\\u003cTypeName\u003e\\` — error on mismatch), and a panicking convenience (\\`Must\\\u003cTypeName\u003e\\` — for compile-time-known constants).\n\n```go\nfunc RenderPublisher(spec *ir.Spec) (string, error)\n```\nRenderPublisher emits the publisher Go source for every \\`action: send\\` operation in spec. Returns \"\" when the spec has no send operations — caller should skip emission entirely and not pull in context/json/fmt imports.\n\n```go\nfunc RenderSubscriber(spec *ir.Spec) (string, error)\n```\nRenderSubscriber emits the subscriber Go source for every \\`action: receive\\` operation. Receive ops are grouped by their resolved queue name: a queue with one op renders the single-message block (unchanged since v0.2); a queue shared by several ops renders the v0.7 combined block. Returns \"\" when the spec has no receive ops — caller should skip emission and not pull in context/json/fmt/errors.\n\n## Types\n\n```go\ntype Config struct {\n\tPackage string\n\tOutput  string\n\t// Initialisms supplements DefaultInitialisms when configuring\n\t// go-jsonschema's --capitalization rules. Empty means defaults only.\n\tInitialisms []string\n\t// SchemaPackages drives cross-tree $ref → import behaviour. For each\n\t// entry, go-jsonschema emits `import alias \"package\"` at the use\n\t// site instead of inlining the schema's types.\n\tSchemaPackages []SchemaPackageMapping\n\t// MessagePackages drives cross-file MESSAGE $ref → import behaviour.\n\t// When a message slot is a $ref into another spec file, the lowerer\n\t// looks up the file in this mapping; the message-name segment of\n\t// the $ref becomes the Go type name in the mapped package. Generated\n\t// Subscriber/Publisher signatures reference `\u003calias\u003e.\u003cTypeName\u003e`\n\t// from the imported package — no payload schema duplication. v0.5+.\n\tMessagePackages []MessagePackageMapping\n\t// OmitValidation suppresses go-jsonschema's generated UnmarshalJSON\n\t// methods (required-field checks, strict additionalProperties,\n\t// format/enum/numeric-bound validators, etc.). False (the default)\n\t// means validation is included; true is the opt-out for consumers\n\t// that hand-write their own UnmarshalJSON, e.g. for wire-compat\n\t// (camelCase ↔ legacy PascalCase): two UnmarshalJSON methods on the\n\t// same type would be a compile error, so wire-compat consumers must\n\t// opt out here to define their own.\n\tOmitValidation bool\n\t// OmitPublishers / OmitSubscribers skip the corresponding generated\n\t// section even when the spec has matching `action:` operations.\n\t// OR-merged with the spec extension equivalents. v0.2+.\n\tOmitPublishers  bool\n\tOmitSubscribers bool\n\t// Warn, when set, receives each warning: go-jsonschema's about a\n\t// schema keyword the generated code doesn't check, reported while\n\t// it generates the payload types, and aapi-codegen's own about\n\t// keywords beside a message payload's $ref and about channel\n\t// parameters declared in the AsyncAPI 2.x shape. Nil discards them.\n\t// Warnings don't make Generate fail.\n\tWarn func(msg string)\n}\n```\nConfig is the internal codegen surface. The user-facing YAML Configuration translates into this via Configuration.ToCodegenConfig.\n\n```go\ntype Configuration struct {\n\tPackage         string                  `yaml:\"package\"`\n\tOutput          string                  `yaml:\"output\"`\n\tSchemaPackages  []SchemaPackageMapping  `yaml:\"schema-packages\"`\n\tMessagePackages []MessagePackageMapping `yaml:\"message-packages\"`\n\t// Capitalization mirrors go-jsonschema's --capitalization flag list.\n\t// When empty, DefaultInitialisms is applied.\n\tCapitalization []string `yaml:\"capitalization\"`\n\t// OmitValidation opts out of go-jsonschema's generated UnmarshalJSON\n\t// methods. Default false (validation included). Set true only when\n\t// consumers will hand-write their own UnmarshalJSON (e.g. for the\n\t// camelCase ↔ legacy PascalCase wire-compat pattern); a generated\n\t// UnmarshalJSON and a hand-written one on the same type is a\n\t// compile error.\n\tOmitValidation bool `yaml:\"omit-validation\"`\n}\n```\nConfiguration 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.\n\nFields not set in YAML default to zero; CLI flags supersede YAML values when both are present (the precedence is established by MergeFlags).\n\n```go\nfunc LoadConfiguration(path string) (*Configuration, error)\n```\nLoadConfiguration 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.\n\n```go\nfunc (c *Configuration) MergeFlags(pkg, output string, capitalization []string)\n```\nMergeFlags 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.\n\n```go\nfunc (c *Configuration) ToCodegenConfig() Config\n```\nToCodegenConfig 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.\n\n```go\ntype MessagePackageMapping struct {\n\tFile    string `yaml:\"file\"`\n\tPackage string `yaml:\"package\"`\n\tAlias   string `yaml:\"alias\"`\n}\n```\nMessagePackageMapping ties a referenced AsyncAPI spec file (consumed via cross-file message $ref) to the Go package the producer's already-generated message types live in. See loader.MessagePackageMapping for the field semantics — this type is the codegen-internal mirror (loader can't import codegen without a cycle; Generate converts at the boundary). v0.5+.\n\n```go\ntype SchemaPackageMapping struct {\n\tID      string `yaml:\"id\"`\n\tPackage string `yaml:\"package\"`\n\tAlias   string `yaml:\"alias\"`\n}\n```\nSchemaPackageMapping 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.\n\n","path":"github.com/plheide/aapi-codegen/pkg/codegen","name":"codegen","synopsis":"Package codegen orchestrates AsyncAPI → Go generation.","isRedistributable":true}
