Schema

Struct Schema 

Source
pub struct Schema {
    pub type: i32,
    pub format: String,
    pub description: String,
    pub nullable: bool,
    pub enum: Vec<String>,
    pub items: Option<Box<Schema>>,
    pub max_items: i64,
    pub min_items: i64,
    pub properties: HashMap<String, Schema>,
    pub required: Vec<String>,
}
Expand description

The Schema object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an OpenAPI 3.0 schema object.

Fields§

§type: i32

Required. Data type.

§format: String

Optional. The format of the data. This is used only for primitive datatypes. Supported formats: for NUMBER type: float, double for INTEGER type: int32, int64 for STRING type: enum

§description: String

Optional. A brief description of the parameter. This could contain examples of use. Parameter description may be formatted as Markdown.

§nullable: bool

Optional. Indicates if the value may be null.

§enum: Vec<String>

Optional. Possible values of the element of Type.STRING with enum format. For example we can define an Enum Direction as : {type:STRING, format:enum, enum:[“EAST”, NORTH“, “SOUTH”, “WEST”]}

§items: Option<Box<Schema>>

Optional. Schema of the elements of Type.ARRAY.

§max_items: i64

Optional. Maximum number of the elements for Type.ARRAY.

§min_items: i64

Optional. Minimum number of the elements for Type.ARRAY.

§properties: HashMap<String, Schema>

Optional. Properties of Type.OBJECT.

§required: Vec<String>

Optional. Required properties of Type.OBJECT.

Implementations§

Source§

impl Schema

Source

pub fn new(typ: SchemaType) -> Self

Constructs a new schema for the specified primitive type.

Source

pub fn new_object() -> Self

Creates a new schema for an object type.

Source

pub fn new_array() -> Self

Creates a new schema for an array type.

Source

pub fn new_number() -> Self

Creates a new schema for a number type.

Source

pub fn new_integer() -> Self

Creates a new schema for an integer type.

Source

pub fn new_string() -> Self

Creates a new schema for a string type.

Source

pub fn format(self, format: SchemaFormat) -> Self

Sets the format of the schema.

This is used for primitive types like int32, int64, float, double, or enum.

Source

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

Sets the description of the schema.

The description can be formatted as Markdown.

Source

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

Sets whether the schema value may be null.

Source

pub fn into_enum<I, S>(self, enum: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Sets the possible enum values for a String type.

This method automatically sets the schema’s type to String and its format to Enum. The values provided will be added to the enum field.

§Example
let enum_schema = Schema::new_string()
    .into_enum(["EAST", "NORTH", "SOUTH", "WEST"]);
Source

pub fn items(self, items: Schema) -> Self

Sets the schema for the elements of an Array type.

This method is only effective when the schema’s type is Array. It specifies the structure of the items contained within the array.

§Example

For a Vec<String>, you would define the schema like this:

let string_array_schema = Schema::new_array()
    .items(Schema::new_string());
Source

pub fn max_items(self, max_items: i64) -> Self

Sets the maximum number of elements for an Array schema.

This method is only effective when the schema’s type is Array.

Source

pub fn min_items(self, min_items: i64) -> Self

Sets the minimum number of elements for an Array schema.

This method is only effective when the schema’s type is Array.

Source

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

Adds a single property to an Object schema.

This method is a convenience for adding a single key-value pair to the properties map. It’s only effective when the schema’s type is Object.

§Arguments
  • name - The name of the property.
  • schema - The schema definition for the property.
Source

pub fn properties<I, S>(self, properties: I) -> Self
where I: IntoIterator<Item = (S, Schema)>, S: Into<String>,

Sets the properties for an Object schema.

This method is only effective when the schema’s type is Object.

§Arguments
  • properties - An iterator of key-value pairs where the key is the property name and the value is the property’s Schema.
Source

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

Adds a required field to an Object schema.

This method is only effective when the schema’s type is Object.

§Arguments
  • name - The name of the property that is now required.
Source

pub fn required<I, S>(self, required: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Sets the list of all required properties for an Object schema.

This method is only effective when the schema’s type is Object.

§Arguments
  • required - An iterator of property names that must be present.
Source§

impl Schema

Source

pub fn type(&self) -> Type

Returns the enum value of type, or the default if the field is set to an invalid enum value.

Source

pub fn set_type(&mut self, value: Type)

Sets type to the provided enum value.

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

Returns the “default value” for a type. Read more
Source§

impl Message for Schema

Source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter.
Source§

fn clear(&mut self)

Clears the message, resetting all fields to their default.
Source§

fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message to a buffer. Read more
Source§

fn encode_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message to a newly allocated buffer.
Source§

fn encode_length_delimited( &self, buf: &mut impl BufMut, ) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message with a length-delimiter to a buffer. Read more
Source§

fn encode_length_delimited_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message with a length-delimiter to a newly allocated buffer.
Source§

fn decode(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes an instance of the message from a buffer. Read more
Source§

fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes a length-delimited instance of the message from the buffer.
Source§

fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes an instance of the message from a buffer, and merges it into self. Read more
Source§

fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes a length-delimited instance of the message from buffer, and merges it into self.
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 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 UnwindSafe for Schema

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> 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic_veecore::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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