Skip to main content

Schema

Struct Schema 

Source
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: SchemaType

Schema 类型

§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

Source

pub fn string() -> Self

创建字符串 Schema

Source

pub fn integer() -> Self

创建整数 Schema

Source

pub fn number() -> Self

创建数字 Schema

Source

pub fn boolean() -> Self

创建布尔 Schema

Source

pub fn array(items: Schema) -> Self

创建数组 Schema

Source

pub fn object() -> Self

创建对象 Schema

Source

pub fn title(self, title: impl Into<String>) -> Self

设置标题

Source

pub fn description(self, desc: impl Into<String>) -> Self

设置描述

Source

pub fn property(self, name: impl Into<String>, schema: Schema) -> Self

添加属性

Source

pub fn required(self, fields: Vec<&str>) -> Self

设置必需属性

Source

pub fn enum_values(self, values: Vec<Value>) -> Self

设置枚举值

Source

pub fn with_default(self, value: Value) -> Self

设置默认值

Source

pub fn example(self, value: Value) -> Self

设置示例值

Source

pub fn format(self, format: impl Into<String>) -> Self

设置格式

Source

pub fn pattern(self, pattern: impl Into<String>) -> Self

设置正则模式

Source

pub fn min_length(self, len: usize) -> Self

设置最小长度

Source

pub fn max_length(self, len: usize) -> Self

设置最大长度

Source

pub fn minimum(self, min: f64) -> Self

设置最小值

Source

pub fn maximum(self, max: f64) -> Self

设置最大值

Source

pub fn nullable(self, nullable: bool) -> Self

设置可为空

Source

pub fn read_only(self, read_only: bool) -> Self

设置只读

Source

pub fn write_only(self, write_only: bool) -> Self

设置只写

Source

pub fn one_of(self, schemas: Vec<Schema>) -> Self

设置 oneOf

Source

pub fn any_of(self, schemas: Vec<Schema>) -> Self

设置 anyOf

Source

pub fn all_of(self, schemas: Vec<Schema>) -> Self

设置 allOf

Source

pub fn to_json_schema(&self) -> Value

转换为 JSON Schema

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Self

创建默认的 Schema(Object 类型)

Source§

impl<'de> Deserialize<'de> for Schema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Schema

Source§

fn eq(&self, other: &Schema) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Schema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Schema

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,