本页尚未翻译
下面显示的是英文原文。
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
- Macros
- Manual
/// 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(", "))),
}
}
/// An audit record another team publishes, with no schema shipped for it.
#[derive(Debug, Deserialize)]
struct AuditRecord {
action: String,
}
struct Record;
impl Handle<AuditRecord> for Record {
fn handle(
&self,
entry: &AuditRecord,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<(), HandlerOutcome>> {
tracing::info!(action = %entry.action, "audited");
ready(Ok(()))
}
}
/// 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(", "))),
}
}