Configuration reference

Configuration reference #

Configuration is set in a single YAML file, that may contain the attributes described below. All attributes are optional, and if not set, the tool uses the default values.

Config #

AttributeTypeDefaultDescription
configVersionint1Configuration version. Now only the 1 is valid value
projectModulestringProject module name for the generated code. If empty, takes from go.mod in the current working directory
runtimeModulestringgithub.com/bdragon300/go-asyncapi/runPath to runtime module with auxiliary code
layout[]LayoutDefault layoutGenerated code layout rules
locatorLocatorReference locator settings
implementations[]ImplementationPer-protocol implementations generation settings
codeCodeCode generation settings
clientClientNo-code client building settings
infraInfraInfra files generation settings

Layout #

AttributeTypeDefaultDescription
nameRestringCondition: regex to match the entity name
artifactKinds[]stringCondition: match to one of artifact kinds in list
moduleURLRestringCondition: regex to match the document URL or path
pathRestringCondition: regex to match the artifact path inside a document (e.g. #/channels/myChannel)
protocols[]stringCondition: match to any protocol in list
notboolfalseIf true, apply NOT operations to the match
renderLayoutRenderRender settings
reusePackagePathstringPath to the Go package to reuse the code from.

Right before the rendering stage, go-asyncapi compiles the “artifacts” (intermediate representation objects) from the AsyncAPI document. To determine how and where their generated code should be rendered to, it checks every artifact one-by-one against all rules in the layout.

If the artifact matches a rule, go-asyncapi generates its code and writes it to the file from the matched rule with given settings. After that it goes to the next rule, and so on, until all rules are checked.

If the artifact does not match any rule, it is skipped and not rendered.

Several conditions in one layout rule are joined via AND operation.

For more examples of the layout rules, see the Code layout page.

LayoutRender #

AttributeTypeDefaultDescription
filestringRequired. Template expression with output file name. Dot is tmpl.CodeTemplateContext
packagestringDirectory namePackage name if it differs from the directory name
protocols[]stringAll supported protocolsProtocols that are allowed to render
protoObjectsOnlyboolfalseIf true, render only the protocol-specific entity code (e.g. Channel1Kafka, but skip Channel1)
templatestringmain.tmplRoot template name, used for rendering.

Locator #

AttributeTypeDefaultDescription
allowRemoteReferencesboolfalsetrue allows reading remote $refs (denied by default by security reasons)
searchDirectorystring.Directory to search for local files referenced by $refs.
timeouttime.Duration30sReference resolving timeout (sets both the HTTP request timeout and command execution timeout)
commandstringShell command of custom locator. If empty, uses the built-in locator.

For more information about the reference locator, see the References page.

Implementation #

AttributeTypeDefaultDescription
protocolstringProtocol
namestringImplementation name.
disableboolfalseIf true, disables the implementation code generation.
directorystringTemplate expression with the output directory name, relative to the target directory. By default, takes from code.implementationsDir setting. Dot is tmpl.ImplTemplateContext
packagestringPackage name if it differs from the directory name
reusePackagePathstringPath to the Go package to reuse the code from.

Code #

AttributeTypeDefaultDescription
onlyPublishboolfalseIf true, generates only the publish code
onlySubscribeboolfalseIf true, generates only the subscribe code
disableFormattingboolfalseIf true, disables applying the go fmt to the generated code
targetDirstring./asyncapiTarget directory name, relative to the current working directory
templatesDirstringDirectory with custom templates
preambleTemplatestringpreamble.tmplPreamble template name, used for rendering.
disableImplementationsboolfalseIf true, disables the implementations code generation.
implementationsDirstringimpl/{{ .Manifest.Protocol }}Template expression with the implementations directory name, relative to the target directory. Dot is tmpl.ImplTemplateContext

If both onlyPublish and onlySubscribe are false or omitted, the tool generates both publish and subscribe code.

Client #

AttributeTypeDefaultDescription
outputFilestring./clientOutput executable file name
outputSourceFilestringclient.goName of temporary file with client source code
keepSourceboolfalseIf true, do not remove the source code file after the build process
goModTemplatestringgo.mod.tmplTemplate name for the client’s go.mod file
tempDirstringTemporary build directory. If empty, use the system’s temporary directory

Infra #

AttributeTypeDefaultDescription
serverOpts[]InfraServerOptAdditional options for servers generation, such as ServerVariable values
enginestringdockerTarget infra engine
outputFilestring./docker-compose.yamlOutput file name

InfraServerOpt #

AttributeTypeDefaultDescription
serverNamestringRequired. Server name (key in document)
variablesmap[string]string, []map[string]stringServer variables values. May be a key-value object or list of key-value objects

Notes #

Template expressions #

Some configuration attributes supports the template expressions, which are evaluated to the string value on tool running. This allows automatically set a value dynamically, depending on the current object or other context.

The template expression is just a Go text/template expression. Couple of examples:

file: {{.Object.Kind}}s/{{.Object | goIDUpper }}.go

Given a particular object, this expression produces the value like channels/my_channel.go.

For more information about the template expressions, see the templating guide.

Protocols and implementations #

Full list of supported protocols and implementations is available by list-implementations CLI subcommand.

Artifact kind #

Every artifact (an intermediate representation object, keeping in memory) generated from the AsyncAPI entity has a kind property. Kind is a string enum, for example, “schema”, “server”, “channel”, “operation”, etc.

Full list is available in the artifact.go.