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.

By default, go-asyncapi reads the configuration file named go-asyncapi.yaml or go-asyncapi.yml in the current working directory if it exists. You may set you own location by passing the -c CLI option.

See also default configuration file

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
templatesDirstringDirectory with custom templates
locatorLocatorReference locator settings
codeCodeCode generation settings
clientClientNo-code client building settings
infraInfraInfra files generation settings
diagramDiagramDiagram generation settings
uiUIWeb UI generation settings

Locator #

AttributeTypeDefaultDescription
allowRemoteReferencesboolfalsetrue allows reading remote $refs (denied by default by security reasons)
rootDirectorystringThe base directory to locate the files. Not used if empty.
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.

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
layout[]LayoutDefault layoutGenerated code layout rules
preambleTemplatestringpreamble.tmplPreamble template name, used for rendering.
utilUtilUtility code generation settings
implementation[]ImplementationPer-protocol implementations generation settings

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

Layout #

For more info see the Code layout page.

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
renderLayoutRenderLayout rule rendering options

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

LayoutRender #

AttributeTypeDefaultDescription
filestringRequired. Template expression with output file name. Dot is tmpl.CodeTemplateContext
packagestringPackage name. If empty, takes from file’s directory name
protocols[]stringProtocols that are allowed to render. Empty list means no restriction
templatestringmain.tmplRoot template name

Util #

AttributeTypeDefaultDescription
directorystringproto/{{ .Protocol }}Template expression with output directory name, relative to the target directory. Dot is tmpl.CodeExtraTemplateContext
custom[]UtilProtocolPer-protocol util code customization options

UtilProtocol #

AttributeTypeDefaultDescription
protocolstringRequired. Protocol
templateDirectorystringDirectory with custom templates

Implementation #

AttributeTypeDefaultDescription
directorystringproto/{{ .Protocol }}Template expression with output directory name for all protocols, relative to the target directory. Dot is tmpl.CodeExtraTemplateContext
disableboolfalseIf true, disable generating the implementations for all protocols
custom[]ImplementationProtocolPer-protocol implementation code customization options

ImplementationProtocol #

AttributeTypeDefaultDescription
protocolstringRequired. Protocol
namestringImplementation name.
disableboolfalseIf true, disables the implementation code generation. Overrides the global implementation disable
templateDirectorystringDirectory with custom templates
packagestringPackage name if it differs from the directory name

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 finished
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

Diagram #

AttributeTypeDefaultDescription
formatstringsvgOutput diagram format. Possible values: svg, d2
outputFilestringOutput file name. If empty, same as name of an input document. Has no effect on rendering multiple files.
targetDirstring.Directory where to place the output files
multipleFilesboolGenerate one diagram file per each source AsyncAPI document instead of all in one diagram. Discards the –output option effect
disableFormattingboolDo not run the d2 file formatter. Only applies when output format is d2
channelsCentricboolGenerate the channels-centric diagram
serversCentricboolGenerate the servers-centric diagram
documentBordersboolDraw document borders in the diagram
d2DiagramD2D2 engine options

DiagramD2 #

AttributeTypeDefaultDescription
enginestringelkD2 layout engine to use. Possible values: elk, dagre
directionstringrightDiagram draw direction. Possible values: up, down, right, left
themeIdint64Theme id to use in diagram. More info
darkThemeIdint64Dark theme id to use in diagram. More info
padint64100Diagram padding in pixels
sketchboolDraw diagram in sketchy style
centerboolCenter the diagram in the output canvas
scalefloat64Scale factor
elkDiagramD2ELKD2 ELK engine options
dagreDiagramD2DagreD2 Dagre engine options

DiagramD2ELK #

AttributeTypeDefaultDescription
algorithmstringlayeredLayout algorithm to use. Possible values: layered, force, radial, mrtree, disco, rectpacking
nodeSpacingint6470Spacing to be preserved between any pair of nodes of two adjacent layers
paddingstring[top=50,left=50,bottom=50,right=50]Expression of padding to be left to a parent element’s border when placing child elements
edgeSpacingint6440Spacing to be preserved between nodes and edges that are routed next to the node’s layer
selfLoopSpacingint6450Spacing to be preserved between a node and its self loops

DiagramD2Dagre #

AttributeTypeDefaultDescription
nodeSepint6460Number of pixels that separate nodes
edgeSepint6420Number of pixels that separate edges

UI #

AttributeTypeDefaultDescription
outputFilestringOutput HTML file name. If empty, same input document name with “.html” extension. Has no effect on “listening” mode
listenboolfalseEnable listening mode using the internal web server
listenAddressstring:8090Host/port to serve the UI in listening mode
listenPathstring/URL base path to serve the UI in listening mode
bundleboolfalseMake a bundle. See also Bundling the assets
bundleDirstringIf not empty, get assets to bundle from directory instead of using default assets. See also Custom assets

Notes #

Template expressions #

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

The template expression is just a Go text/template expression. For example:

file: {{.Object.Kind}}s/{{ goID .Object }}.go

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

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

Protocols and implementations #

Full list of implementations built-in for particular protocols is available by list-implementations CLI subcommand.

Artifact kind #

For more info about artifacts see Internals article.

Every artifact generated from the AsyncAPI entity has a kind, which is a string enum, for example, “schema”, “server”, “channel”, “operation”, etc.

Full list is available in the artifact.go.