Validator

The validator stage lives in the validator package. To add a rule, follow Adding a validation rule.

What it does

The validator applies read-only rules to the linked model that the parser produced and reports findings. A finding has a rule, a message, a source location, and a documentation link. Errors stop the load; warnings are returned with the document.

Contract

  • Input: the linked AsyncApiDocument, or a document or fragment loaded for a reference, and the per-load AsyncApiContext.
  • Output: a ValidationReport with the findings in document order.
  • Invariants:
  • The validator never changes the model. Reference links come from the parser; the validator only reports their problems.
  • Each object is checked once per run, under the name of the first path that reaches it.
  • Every finding uses the documentation link of its rule.

Steps

  1. Loaded targets. Each external document and fragment is validated on its own, as the kind of object its reference expects.
  2. Root document. The root document is walked in document order. An inline object is checked by the rules of its kind. A $ref reports its link problems and queues the object it leads to.
  3. Unreached targets. Queued targets that no path reached are checked after the walk.
  4. Document rules. Rules that relate objects across the whole document run last, such as root operations using root channels.

Rules

  • A rule set checks its object and walks its children through the shared walk, so findings keep document order. It never resolves a reference or builds another rule set.
  • A rule is identified by a stable code, a concern, a severity, and a documentation link. The prefix of the code states the authority: AAS3- for the AsyncAPI specification, JSONSCHEMA- for JSON Schema, GEN- for generator limits, and ADV- for advisories. The rule inventory lists them all.
  • Messages start with a path that names the object, such as Channel 'orders' Message 'created'.
  • Protocol binding rules are looked up by protocol.

What it does not do

The validator does not read files, link references, bundle, or decide what a generator can produce for one output. Generation compatibility is checked by the generator; see the validation boundary.

Tests

Validator tests are under asyncapi-generator-core/src/test/kotlin/dev/banking/asyncapi/generator/core/validator, with fixtures in asyncapi-generator-core/src/test/resources/validator.