Parser
The parser stage lives in the parser package, with the loader in loader and
the per-load state in context. Its detailed rules are in the
parser contract.
What it does
The parser turns the document tree of the root contract into one complete,
linked model: the AsyncAPI document plus every external document and fragment
its references point at, with every $ref linked to its target. It records
where each model came from, so later stages can point diagnostics at a line in
the right file.
Contract
- Input: the root
InputDocumentfrom the reader. - Output: an
AsyncApiDocument, the documents and fragments loaded for its references, and the per-loadAsyncApiContextthat tracks sources, node locations, models, and reference links. - Invariants:
- The model is built only from the document tree; the parser never re-reads text.
- Every model is registered with the node it was built from.
- After loading, every reference has a link: resolved, unresolved, a cycle, or a target of the wrong kind. Linking never reports; the validator turns link problems into findings.
- Each external document is read once, and each fragment is parsed once per kind and parser profile, however many references reach it.
Steps
A load runs four steps in order: parse, load, link, validate. The first three belong to the parser.
- Parse. The declared
asyncapiversion selects a parser profile, which defines the allowed members of every fixed-field object. The root object is mapped to anAsyncApiDocument. Every$refis recorded with how its target is to be parsed. - Load. The recorded references are followed depth first, in the order the parser met them. A reference into another file reads that file. A target in an AsyncAPI document parses the whole document once; any other target is parsed as the kind of object its reference expects. References found in a loaded target are followed before the next one. A budget counts documents, targets, depth, and bytes across the whole load.
- Link. Every reference is followed to the model it points at.
- Validate. See the validator.
Parse and load failures are structured diagnostics with a stable code and a source location. All of them are reported before any validation finding.
What it does not do
The parser does not apply semantic rules: whether a reference points at the right kind of object, whether a schema is supported, or whether names are valid is decided by the validator. It does not bundle references or generate code.
Known limitations
- Only the AsyncAPI 3.0 parser profile is implemented. 3.1 documents are recognized and rejected with a diagnostic.
- References to remote (
http:) documents are not supported. - A load stops at its first parse or load failure.
Tests
Parser tests are under
asyncapi-generator-core/src/test/kotlin/dev/banking/asyncapi/generator/core/parser,
grouped by AsyncAPI object. AsyncApiDocumentLoaderTest in the loader test
package covers the four steps together.