pub enum Schema {
Reference {
reference: String,
},
Object(Box<SchemaObject>),
Any(Value),
}Expand description
JSON Schema object
Flexible representation that can hold any valid JSON Schema. This type supports
both schema references (using $ref) and complete inline schema definitions.
Schemas define the structure and validation rules for message payloads, following the JSON Schema specification.
§Example
§Reference Schema
use asyncapi_rust_models::Schema;
let schema = Schema::Reference {
reference: "#/components/schemas/ChatMessage".to_string(),
};§Object Schema
use asyncapi_rust_models::{Schema, SchemaObject};
use indexmap::IndexMap;
let schema = Schema::Object(Box::new(SchemaObject {
schema_type: Some(serde_json::json!("object")),
properties: None,
required: Some(vec!["username".to_string(), "room".to_string()]),
description: Some("A chat message".to_string()),
title: Some("ChatMessage".to_string()),
enum_values: None,
const_value: None,
items: None,
additional_properties: None,
one_of: None,
any_of: None,
all_of: None,
additional: IndexMap::new(),
}));Variants§
Reference
Reference to another schema ($ref)
Points to a reusable schema definition in the components section. Format: “#/components/schemas/{schemaName}”
Object(Box<SchemaObject>)
Full schema object (boxed to reduce enum size)
Contains a complete JSON Schema definition with all properties inline
Any(Value)
Catch-all for valid JSON Schemas that don’t match the above variants
Handles minimal schemas like {}, {"title": "..."}, or boolean schemas
(true/false) that are valid per the JSON Schema spec but carry no
structural information. schemars emits these for open-ended types such
as serde_json::Value.