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
impl Schema
Sourcepub fn new(typ: SchemaType) -> Self
pub fn new(typ: SchemaType) -> Self
Constructs a new schema for the specified primitive type.
Sourcepub fn new_object() -> Self
pub fn new_object() -> Self
Creates a new schema for an object type.
Sourcepub fn new_number() -> Self
pub fn new_number() -> Self
Creates a new schema for a number type.
Sourcepub fn new_integer() -> Self
pub fn new_integer() -> Self
Creates a new schema for an integer type.
Sourcepub fn new_string() -> Self
pub fn new_string() -> Self
Creates a new schema for a string type.
Sourcepub fn format(self, format: SchemaFormat) -> Self
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
.
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Sets the description of the schema.
The description can be formatted as Markdown.
Sourcepub fn into_enum<I, S>(self, enum: I) -> Self
pub fn into_enum<I, S>(self, enum: I) -> Self
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"]);
Sourcepub fn items(self, items: Schema) -> Self
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());
Sourcepub fn max_items(self, max_items: i64) -> Self
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
.
Sourcepub fn min_items(self, min_items: i64) -> Self
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
.
Sourcepub fn property(self, name: impl Into<String>, schema: Schema) -> Self
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.
Sourcepub fn properties<I, S>(self, properties: I) -> Self
pub fn properties<I, S>(self, properties: I) -> Self
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’sSchema
.
Sourcepub fn required_field(self, name: impl Into<String>) -> Self
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.
Trait Implementations§
Source§impl Message for Schema
impl Message for Schema
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Source§fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>where
Self: Sized,
fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>where
Self: Sized,
Source§fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Source§fn encode_length_delimited(
&self,
buf: &mut impl BufMut,
) -> Result<(), EncodeError>where
Self: Sized,
fn encode_length_delimited(
&self,
buf: &mut impl BufMut,
) -> Result<(), EncodeError>where
Self: Sized,
Source§fn encode_length_delimited_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_length_delimited_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Source§fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Source§fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Source§fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
self
. Read moreSource§fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
self
.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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic_veecore::Request