pub enum Schema {
Bool(bool),
Object(Box<SchemaObject>),
}Expand description
A JSON Schema.
A boolean is a valid schema in JSON Schema 2020-12: true accepts every
instance and false accepts none. That is why this is an enum rather than a
struct.
Schema::Bool(true) is how a genuinely unconstrained
payload is represented. Kynos never produces it by accident — a Rust type
that cannot describe itself has no Schema implementation at all, and the
permissive schema is reachable only by naming it in the handler signature.
Variants§
Bool(bool)
The trivially true (true) or trivially false (false) schema.
Object(Box<SchemaObject>)
A schema with keywords.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn of_type(ty: SchemaType) -> Self
pub fn of_type(ty: SchemaType) -> Self
A schema constrained to a single primitive type.
Sourcepub fn nullable(ty: SchemaType) -> Self
pub fn nullable(ty: SchemaType) -> Self
A schema that is ty or null.
This is how nullability is expressed from OpenAPI 3.1 onward. The 3.0
nullable: true keyword does not exist and must never be emitted.
Sourcepub fn reference(uri: impl Into<String>) -> Self
pub fn reference(uri: impl Into<String>) -> Self
A $ref to another schema.
Unlike a Ref, sibling keywords on a schema $ref are
applied rather than ignored.
Sourcepub fn as_object(&self) -> Option<&SchemaObject>
pub fn as_object(&self) -> Option<&SchemaObject>
Returns the keyword-carrying form, if this is not a boolean schema.