Skip to main content

Schema

Enum Schema 

Source
pub enum Schema {
    Ref {
        ref_path: String,
    },
    Object(ObjectType),
    Array(ArrayType),
    Primitive(PrimitiveSchema),
}
Expand description

Schema 定义,支持引用、对象、数组、基本类型

  • Ref:通过 $ref 引用 components.schemas 中定义的 Schema
  • Object:对象类型,包含 properties 和 required
  • Array:数组类型,包含 items
  • Primitive:基本类型(string/integer/number/boolean)

Variants§

§

Ref

引用其他已定义的 Schema

Fields

§ref_path: String
§

Object(ObjectType)

对象类型

§

Array(ArrayType)

数组类型

§

Primitive(PrimitiveSchema)

基本类型(string/integer/number/boolean)

Implementations§

Source§

impl Schema

Source

pub fn ref_to(name: &str) -> Self

创建一个引用 Schema

Source

pub fn object(obj: ObjectType) -> Self

创建一个对象 Schema

Source

pub fn array(arr: ArrayType) -> Self

创建一个数组 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 is_ref(&self) -> bool

判断是否为引用类型

Source

pub fn is_object(&self) -> bool

判断是否为对象类型

Source

pub fn is_array(&self) -> bool

判断是否为数组类型

Source

pub fn with_format(self, format: &str) -> Self

设置 format(仅对 Primitive 类型有效,其他类型返回原值)

Source

pub fn with_description(self, desc: &str) -> Self

设置描述(仅对 Primitive 类型有效)

Source

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

设置示例值(仅对 Primitive 类型有效)

Source

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

设置默认值(仅对 Primitive 类型有效)

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<'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 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

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more