Skip to main content

messages_without_schema

messages_without_schema lists the messages the document describes with no payload schema, for a check to fail on.

A message without a schema documents its channel but not its shape, and a client generator has no type to produce from it. build_spec logs one warning per gap when it builds the document; this method returns the same list as component names. A test or a release check asserts on it. Messages whose bytes are their own format, on a byte lane, are left out: they have no schema by design. On the attribute path a gap is a message type without a JsonSchema derive. A subscriber(..) registration has one only after undocumented. The example runs with cargo test --example asyncapi_schemas --features macros,memory,asyncapi.

Example​

/// An audit record another team publishes, with no schema shipped for it.
#[derive(Debug, Deserialize)]
struct AuditRecord {
action: String,
}

#[subscriber("audit")]
async fn record(entry: &AuditRecord) -> HandlerOutcome {
tracing::info!(action = %entry.action, "audited");
HandlerOutcome::ack()
}

/// The release check: every message in the document has a schema, or the check names the ones
/// that do not.
fn check_schemas(spec: &Spec) -> Result<(), String> {
match spec.messages_without_schema().as_slice() {
[] => Ok(()),
gaps => Err(format!("no payload schema for {}", gaps.join(", "))),
}
}