pub struct Schema {Show 21 fields
pub title: Option<String>,
pub description: Option<String>,
pub schema_type: SchemaType,
pub properties: Option<BTreeMap<String, Schema>>,
pub required: Option<Vec<String>>,
pub items: Option<Box<Schema>>,
pub enum_values: Option<Vec<Value>>,
pub default: Option<Value>,
pub example: Option<Value>,
pub nullable: bool,
pub read_only: bool,
pub write_only: bool,
pub minimum: Option<f64>,
pub maximum: Option<f64>,
pub min_length: Option<usize>,
pub max_length: Option<usize>,
pub pattern: Option<String>,
pub format: Option<String>,
pub one_of: Option<Vec<Schema>>,
pub any_of: Option<Vec<Schema>>,
pub all_of: Option<Vec<Schema>>,
}Expand description
Schema 定义
Fields§
§title: Option<String>Schema 标题
description: Option<String>Schema 描述
schema_type: SchemaTypeSchema 类型
properties: Option<BTreeMap<String, Schema>>属性定义(仅 Object 类型)
required: Option<Vec<String>>必需属性列表
items: Option<Box<Schema>>数组元素类型(仅 Array 类型)
enum_values: Option<Vec<Value>>枚举值
default: Option<Value>默认值
example: Option<Value>示例值
nullable: bool是否可为空
read_only: bool只读
write_only: bool只写
minimum: Option<f64>最小值(Number/Integer)
maximum: Option<f64>最大值(Number/Integer)
min_length: Option<usize>最小长度(String)
max_length: Option<usize>最大长度(String)
pattern: Option<String>正则模式(String)
format: Option<String>格式(String)
one_of: Option<Vec<Schema>>多个类型(用于 oneOf)
any_of: Option<Vec<Schema>>多个类型(用于 anyOf)
all_of: Option<Vec<Schema>>多个类型(用于 allOf)
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn description(self, desc: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
设置描述
Sourcepub fn enum_values(self, values: Vec<Value>) -> Self
pub fn enum_values(self, values: Vec<Value>) -> Self
设置枚举值
Sourcepub fn with_default(self, value: Value) -> Self
pub fn with_default(self, value: Value) -> Self
设置默认值
Sourcepub fn min_length(self, len: usize) -> Self
pub fn min_length(self, len: usize) -> Self
设置最小长度
Sourcepub fn max_length(self, len: usize) -> Self
pub fn max_length(self, len: usize) -> Self
设置最大长度
Sourcepub fn write_only(self, write_only: bool) -> Self
pub fn write_only(self, write_only: bool) -> Self
设置只写
Sourcepub fn to_json_schema(&self) -> Value
pub fn to_json_schema(&self) -> Value
转换为 JSON Schema
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Schema
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more