{"modulePath":"github.com/plheide/aapi-codegen","version":"v0.13.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package ir\n\nPackage ir is the binding-agnostic intermediate representation that sits between the AsyncAPI loader and the Go-source templates. The loader produces a \\*loader.Document that mirrors the YAML shape; the lowerer turns that into an \\*ir.Spec the templates iterate over.\n\nKeeping the IR binding-agnostic at the top level (channels and operations) and per-binding only at the leaves (Channel.Binding) lets future bindings (Kafka, WebSocket) slot in without rewriting either the templates or the lowerer's spine. v1 ships only AMQP — see amqp.go.\n\n## Types\n\n```go\ntype AMQPBinding struct {\n\t// ChannelKind is the AsyncAPI `bindings.amqp.is` value. \"routingKey\"\n\t// (publisher mode — address is the routing key on Exchange) or\n\t// \"queue\" (consumer mode — address is the queue name; the queue is\n\t// bound to Exchange separately). Empty when `bindings.amqp.is` is\n\t// not declared (legacy v0.1.x specs imply routingKey for publishers).\n\tChannelKind string\n\t// Exchange is the AMQP exchange name from `bindings.amqp.exchange.name`.\n\t// Required for publishers; for consumer-mode channels it's the\n\t// exchange the queue is bound to (informational).\n\tExchange string\n\t// ExchangeType is \"direct\", \"topic\", \"fanout\", or \"headers\". From\n\t// `bindings.amqp.exchange.type`.\n\tExchangeType string\n\t// Queue is the consumer-side queue topology when ChannelKind == \"queue\"\n\t// or when bindings.amqp.queue is declared. Nil for pure publisher\n\t// channels (v0.1.x default).\n\tQueue *AMQPQueue\n\t// BindingVersion mirrors `bindings.amqp.bindingVersion`.\n\tBindingVersion string\n}\n```\nAMQPBinding is the typed view of an AsyncAPI channel's \\`bindings.amqp\\` stanza. v0.1.x captured only the publisher-relevant fields (exchange); v0.2 adds Queue + ChannelKind to drive subscriber emission.\n\n```go\nfunc (*AMQPBinding) Kind() string\n```\nKind satisfies Binding.\n\n```go\ntype AMQPQueue struct {\n\t// Name is the queue name (may be a parameter template — see\n\t// Channel.Address.Params for the typed parameter list).\n\tName string\n\t// Durable / AutoDelete / Exclusive mirror the AsyncAPI fields.\n\t// Defaults are zero-values (false) which matches the AsyncAPI\n\t// default when the field is omitted.\n\tDurable    bool\n\tAutoDelete bool\n\tExclusive  bool\n}\n```\nAMQPQueue mirrors \\`bindings.amqp.queue\\` for consumer-mode channels. When ChannelKind == \"queue\", Name is the same template as the channel address (the address IS the queue name in AsyncAPI 3.x queue mode); the field is preserved here so generated code can reference either.\n\n```go\ntype Action string\n```\nAction is the AsyncAPI operation.action value. Determines which template emits the operation: send → publisher, receive → subscriber.\n\n```go\nconst (\n\t// ActionSend marks a publish operation. The publisher template emits\n\t// a Send\u003cMessageName\u003e method.\n\tActionSend Action = \"send\"\n\t// ActionReceive marks a consume operation. The subscriber template\n\t// emits a \u003cMessageName\u003eHandler interface and a Subscribe\u003cMessageName\u003e\n\t// method (v0.2+).\n\tActionReceive Action = \"receive\"\n)\n```\n\n```go\ntype Address struct {\n\t// Raw is the original address string from the spec, used in\n\t// generated-code comments so the reader can correlate to the YAML.\n\tRaw string\n\t// Parts is the address split on `{name}` boundaries, in order.\n\tParts []AddressPart\n\t// Params is Parts filtered to just the parameter parts, in\n\t// declaration order — the order publisher arguments appear in.\n\tParams []AddressParam\n}\n```\nAddress is a parsed channel-address template. Templated parameters become Param parts; everything else is Literal.\n\n```go\nfunc ParseAddress(s string) (Address, error)\n```\nParseAddress parses an AsyncAPI channel address template into an Address. Parameters use \\`{name}\\` syntax; everything else is literal.\n\nExamples:\n\n\t\"widget.cancellation\"     → Parts: [Literal(\"widget.cancellation\")]\n\t\"{tenant}.{widgetType}\"   → Parts: [Param(\"tenant\"), Literal(\".\"), Param(\"widgetType\")]\n\t\"prefix.{a}.suffix.{b}\"   → Parts: [Literal(\"prefix.\"), Param(\"a\"), Literal(\".suffix.\"), Param(\"b\")]\n\nNested braces and escaping are not supported — AsyncAPI 3.x doesn't define them. An unmatched \\`{\\` is an error.\n\n```go\nfunc (a Address) RoutingKeyExpr() string\n```\nRoutingKeyExpr renders the Go expression that constructs the routing key from the parsed address. For all-literal addresses, returns a Go string literal (\"widget.cancellation\"). For templated addresses, returns a \\`+\\`-concatenation of arg names and quoted literals (a + \".\" + b). Single-parameter addresses become just the arg name.\n\nTyped parameters (GoType != \"string\", e.g. a JobType enum from v0.4) are coerced to string via an explicit \\`string(name)\\` cast so the \\`+\\` concatenation type-checks.\n\n```go\nfunc (a Address) TemplateExpr(tmpl string) (string, error)\n```\nTemplateExpr renders the Go expression for tmpl, a template in address syntax built from this address's parameters, such as a queue name: \"{tenant}.audit-log\" on the address \"{tenant}.orders.created\" gives \\`tenant + \".audit-log\"\\`. Parameters are referenced as RoutingKeyExpr references them, so a typed parameter gets its \\`string(name)\\` cast. A template without parameters gives a quoted literal. A parameter that the address doesn't declare is an error.\n\n```go\ntype AddressParam struct {\n\t// JSONName is the parameter name as it appears in the spec\n\t// address template, e.g. \"tenant\".\n\tJSONName string\n\t// GoArgName is the Go function-argument name the publisher emits.\n\t// Equal to JSONName today; reserved for future name-mangling\n\t// (reserved-keyword escaping etc.).\n\tGoArgName string\n\t// GoType is the Go type emitted in the function signature: \"string\",\n\t// or the enum or pattern type the lowerer registered.\n\tGoType string\n\t// Checked marks a typed parameter whose value the generated method\n\t// checks with the type's Valid method before it publishes or\n\t// subscribes: an enum unless validation is omitted, and a pattern,\n\t// which is typed only when validation isn't omitted.\n\tChecked bool\n}\n```\nAddressParam is a typed view of one channel-address parameter as it surfaces on the generated Publisher and Subscriber method signatures. It is \\`string\\` unless the spec gives the parameter an enum or a pattern, which make it a named type.\n\n```go\ntype AddressPart struct {\n\t// Literal is the raw text segment when this part is a literal,\n\t// empty when it's a parameter.\n\tLiteral string\n\t// Param is the parameter name when this part is a parameter,\n\t// empty when it's a literal.\n\tParam string\n}\n```\nAddressPart is one segment of an address template. Either AddressLiteral or AddressParam — never both. (No interface to keep the template logic trivially branchable.)\n\n```go\nfunc (p AddressPart) IsParam() bool\n```\nIsParam reports whether the part is a parameter reference.\n\n```go\ntype Binding interface {\n\t// Kind returns the binding's protocol identifier (\"amqp\", future:\n\t// \"kafka\", \"ws\"). Templates dispatch on this when more than one\n\t// binding ships.\n\tKind() string\n}\n```\nBinding is the marker interface for protocol-specific channel metadata. v1 has one implementation: \\*AMQPBinding (see amqp.go).\n\n```go\ntype Channel struct {\n\t// Name is the AsyncAPI channel key, e.g. \"widgetDispatch\".\n\tName string\n\t// Address is the parsed channel-address template.\n\tAddress Address\n\t// Binding is the protocol-specific binding metadata. Concrete type\n\t// is *AMQPBinding for v1; future bindings extend this interface.\n\tBinding Binding\n}\n```\nChannel is the AsyncAPI channel an operation publishes to.\n\n```go\ntype Message struct {\n\t// Name is the AsyncAPI message key, e.g. \"WidgetMessage\".\n\tName string\n\t// GoTypeName is the exported Go struct type the payload generates\n\t// to (matches the JSON Schema's `title`, since\n\t// --struct-name-from-title is on, for local messages; the message\n\t// name for imported messages).\n\tGoTypeName string\n\t// ImportedPackage and ImportedAlias are set when the message was\n\t// resolved via x-aapi-codegen.message-packages (cross-file $ref).\n\t// Empty for local messages. v0.5+.\n\tImportedPackage string\n\tImportedAlias   string\n\t// PayloadIsRef is set when the payload schema's root is a $ref. Then\n\t// go-jsonschema generates the type of the schema it points at, so\n\t// GoTypeName may be declared nowhere; it explains that error.\n\tPayloadIsRef bool\n}\n```\nMessage is the resolved payload type the operation publishes/consumes.\n\nTwo flavours, distinguished by ImportedPackage:\n\n  - Local: GoTypeName names a type declared in the generated package (default — the spec defines the payload inline or via a $ref the lowerer materializes).\n  - Imported (v0.5+): the message is a cross-file $ref into another spec's message; the producer's already-generated package supplies the Go type. ImportedPackage is the producer's Go import path, ImportedAlias is the local import alias, GoTypeName is the type name in that package. Generated code references \\`\\\u003cImportedAlias\u003e.\\\u003cGoTypeName\u003e\\`.\n\n```go\nfunc (m *Message) QualifiedGoType() string\n```\nQualifiedGoType returns the type name as the templates should emit it. For local messages this is just GoTypeName. For imported messages it is the alias.TypeName form. Centralising the rendering here keeps templates from having to branch on the imported-vs-local distinction.\n\n```go\ntype Operation struct {\n\t// Name is the AsyncAPI operation key, e.g. \"sendWidgetMessage\" or\n\t// \"consumeWidgetMessage\".\n\tName string\n\t// Action is the operation's AsyncAPI action (send or receive).\n\tAction Action\n\t// GoFuncName is the exported Go method name. For send: \"SendWidgetMessage\"\n\t// (on Publisher). For receive: \"SubscribeWidgetMessage\" (on Subscriber).\n\tGoFuncName string\n\t// HandlerTypeName is the interface name the subscriber generates and\n\t// the consumer code implements. Only set for ActionReceive; empty for\n\t// ActionSend. Form: \u003cMessageName\u003eHandler, e.g. \"WidgetMessageHandler\".\n\tHandlerTypeName string\n\t// HandlerMethodName is the single method on HandlerTypeName the\n\t// consumer implements. Only set for ActionReceive. Form:\n\t// Handle\u003cMessageName\u003e, e.g. \"HandleWidgetMessage\".\n\tHandlerMethodName string\n\t// Channel is the resolved channel this operation targets.\n\tChannel *Channel\n\t// Message is the resolved payload type.\n\tMessage *Message\n\t// PublishDefaults carries AMQP message + operation binding values\n\t// the publisher template wires into the default PublishProperties.\n\t// Nil when the operation has no relevant bindings; the generated\n\t// Send method still accepts SendOption opts but starts from a\n\t// zero-value PublishProperties. v0.3+.\n\tPublishDefaults *PublishDefaults\n}\n```\nOperation is one published or consumed operation. Maps 1:1 to AsyncAPI \\`operations.X\\`. Action distinguishes publisher vs subscriber emission; everything else is shared.\n\n```go\ntype ParameterEnum struct {\n\t// GoTypeName is the exported Go type name (derived from the\n\t// parameter key, pascalized: jobType → JobType).\n\tGoTypeName string\n\t// Values is the ordered list of valid string values; the const\n\t// names are `\u003cGoTypeName\u003e\u003cPascalize(value)\u003e`, e.g. JobTypeBuild.\n\tValues []string\n}\n```\nParameterEnum captures one typed-enum channel parameter — what the publisher / subscriber template needs to emit a Go enum (named type + const block). Two distinct channel parameters that resolve to the same GoTypeName + Values get deduped by the lowerer; collisions on the GoTypeName with mismatching values raise an error.\n\n```go\ntype ParameterPattern struct {\n\t// GoTypeName is the exported Go type name (derived from the\n\t// parameter key, pascalized: shardID → ShardID).\n\tGoTypeName string\n\t// Pattern is the spec-declared regex, in the syntax the Go stdlib\n\t// `regexp` package accepts (RE2). Spec authors who use\n\t// non-RE2 features (lookaround, backreferences) get a clear\n\t// `regexp.MustCompile` failure at generated-package load time —\n\t// catchable in the unit test that imports the package.\n\tPattern string\n}\n```\nParameterPattern captures one pattern-validated channel parameter — what the publisher / subscriber template needs to emit a typed wrapper (\\`type X string\\`) plus New\\\u003cT\u003e/Must\\\u003cT\u003e constructors that regex-check the input before returning. Dedup + collision rules mirror ParameterEnum: same GoTypeName must declare the same Pattern. Suppressed (parameter falls back to plain string) when the spec sets \\`x-aapi-codegen.omit-validation: true\\`.\n\n```go\ntype PublishDefaults struct {\n\t// ContentType from defaultContentType or messages.X.contentType.\n\t// Always set when at least one of the spec sources declares it.\n\tContentType string\n\t// ContentEncoding from messages.X.bindings.amqp.contentEncoding.\n\tContentEncoding string\n\t// MessageType from messages.X.bindings.amqp.messageType.\n\tMessageType string\n\t// Priority from operations.X.bindings.amqp.priority (0-9 in AMQP).\n\tPriority *uint8\n\t// Expiration from operations.X.bindings.amqp.expiration. Per the\n\t// AMQP wire format this is a string-encoded number of milliseconds;\n\t// the IR keeps it as a string to preserve the spec author's exact\n\t// declaration.\n\tExpiration string\n}\n```\nPublishDefaults holds the AMQP message-level + operation-level binding fields the publisher template materialises as default PublishProperties values. Each field is a pointer so the template can distinguish \"spec didn't declare this\" (nil → don't emit a default) from \"spec declared zero\" (non-nil → emit zero).\n\n```go\ntype Spec struct {\n\t// PackageName is the Go package name the templates emit.\n\tPackageName string\n\t// DocTitle is doc.Info.Title, used in publisher comments.\n\tDocTitle string\n\t// Operations is the ordered list of operations to emit (both\n\t// `action: send` and `action: receive` from v0.2).\n\tOperations []*Operation\n\t// ParameterEnums collects every distinct typed-enum parameter the\n\t// templates need to render as a Go enum type + constants. Populated\n\t// by the lowerer from channels.X.parameters.Y.schema when type\n\t// is string and an `enum: [...]` list is declared. v0.4+.\n\tParameterEnums []*ParameterEnum\n\t// ParameterPatterns collects every distinct pattern-validated\n\t// parameter the templates need to render as a typed-wrapper +\n\t// New\u003cT\u003e/Must\u003cT\u003e constructor pair. Populated by the lowerer from\n\t// channels.X.parameters.Y.schema when type is string and a\n\t// `pattern` is declared (and the parameter doesn't already have an\n\t// enum — enum wins the closed-set check). v0.4.1+.\n\tParameterPatterns []*ParameterPattern\n}\n```\nSpec is the root of the IR. One \\*Spec per generated Go package.\n\n","path":"github.com/plheide/aapi-codegen/pkg/codegen/ir","name":"ir","synopsis":"Package ir is the binding-agnostic intermediate representation that sits between the AsyncAPI loader and the Go-source templates.","isRedistributable":true}
