pub struct Schema {
pub deprecated: Option<String>,
pub description: Option<String>,
pub name: Option<String>,
pub nullable: bool,
pub ty: SchemaType,
}Expand description
Describes the metadata and shape of a type.
Fields§
§deprecated: Option<String>§description: Option<String>§name: Option<String>§nullable: bool§ty: SchemaTypeImplementations§
Source§impl Schema
impl Schema
Sourcepub fn new(ty: impl Into<SchemaType>) -> Self
pub fn new(ty: impl Into<SchemaType>) -> Self
Create a schema with the provided type.
Sourcepub fn boolean(value: BooleanType) -> Self
pub fn boolean(value: BooleanType) -> Self
Create a boolean schema.
Sourcepub fn enumerable(value: EnumType) -> Self
pub fn enumerable(value: EnumType) -> Self
Create an enum schema.
Sourcepub fn integer(value: IntegerType) -> Self
pub fn integer(value: IntegerType) -> Self
Create an integer schema.
Sourcepub fn literal(value: LiteralType) -> Self
pub fn literal(value: LiteralType) -> Self
Create a literal schema.
Sourcepub fn literal_value(value: LiteralValue) -> Self
pub fn literal_value(value: LiteralValue) -> Self
Create a literal schema with the provided value.
Sourcepub fn object(value: ObjectType) -> Self
pub fn object(value: ObjectType) -> Self
Create an object schema.
Sourcepub fn string(value: StringType) -> Self
pub fn string(value: StringType) -> Self
Create a string schema.
Sourcepub fn structure(value: StructType) -> Self
pub fn structure(value: StructType) -> Self
Create a struct schema.
Sourcepub fn nullify(&mut self)
pub fn nullify(&mut self)
Convert the current schema to a nullable type. If already nullable, do nothing, otherwise convert to a union.
Sourcepub fn partialize(&mut self)
pub fn partialize(&mut self)
Mark the inner schema type as partial. Only structs and unions can be marked partial, but arrays and objects will also be recursively set to update the inner type.
Methods from Deref<Target = SchemaType>§
Sourcepub fn get_default(&self) -> Option<&LiteralValue>
pub fn get_default(&self) -> Option<&LiteralValue>
Return a default value from the inner schema type.
Sourcepub fn is_nullable(&self) -> bool
pub fn is_nullable(&self) -> bool
Return true if the schema is nullable (a union with a null).
Sourcepub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
Return true if the schema is a reference.
Sourcepub fn set_default(&mut self, default: LiteralValue)
pub fn set_default(&mut self, default: LiteralValue)
Set the default of the inner schema type.
Sourcepub fn add_field(&mut self, key: &str, value: impl Into<SchemaField>)
pub fn add_field(&mut self, key: &str, value: impl Into<SchemaField>)
Add a field to the type if it’s a struct.