utoipa::openapi::schema

Struct Object

Source
#[non_exhaustive]
pub struct Object {
Show 29 fields pub schema_type: SchemaType, pub title: Option<String>, pub format: Option<SchemaFormat>, pub description: Option<String>, pub default: Option<Value>, pub enum_values: Option<Vec<Value>>, pub required: Vec<String>, pub properties: BTreeMap<String, RefOr<Schema>>, pub additional_properties: Option<Box<AdditionalProperties<Schema>>>, pub property_names: Option<Box<Schema>>, pub deprecated: Option<Deprecated>, pub example: Option<Value>, pub examples: Vec<Value>, pub write_only: Option<bool>, pub read_only: Option<bool>, pub xml: Option<Xml>, pub multiple_of: Option<Number>, pub maximum: Option<Number>, pub minimum: Option<Number>, pub exclusive_maximum: Option<Number>, pub exclusive_minimum: Option<Number>, pub max_length: Option<usize>, pub min_length: Option<usize>, pub pattern: Option<String>, pub max_properties: Option<usize>, pub min_properties: Option<usize>, pub extensions: Option<Extensions>, pub content_encoding: String, pub content_media_type: String,
}
Expand description

Implements subset of OpenAPI Schema Object which allows adding other Schemas as properties to this Schema.

This is a generic OpenAPI schema object which can used to present object, field or an enum.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§schema_type: SchemaType

Type of Object e.g. Type::Object for object and Type::String for string types.

§title: Option<String>

Changes the Object title.

§format: Option<SchemaFormat>

Additional format for detailing the schema type.

§description: Option<String>

Description of the Object. Markdown syntax is supported.

§default: Option<Value>

Default value which is provided when user has not provided the input in Swagger UI.

§enum_values: Option<Vec<Value>>

Enum variants of fields that can be represented as unit type enums.

§required: Vec<String>

Vector of required field names.

§properties: BTreeMap<String, RefOr<Schema>>

Map of fields with their Schema types.

With preserve_order feature flag indexmap::IndexMap will be used as properties map backing implementation to retain property order of ToSchema. By default BTreeMap will be used.

§additional_properties: Option<Box<AdditionalProperties<Schema>>>

Additional Schema for non specified fields (Useful for typed maps).

§property_names: Option<Box<Schema>>

Additional Schema to describe property names of an object such as a map. See more details https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#name-propertynames

§deprecated: Option<Deprecated>

Changes the Object deprecated status.

§example: Option<Value>

Example shown in UI of the value for richer documentation.

Deprecated since 3.0.x. Prefer Object::examples instead

§examples: Vec<Value>

Examples shown in UI of the value for richer documentation.

§write_only: Option<bool>

Write only property will be only sent in write requests like POST, PUT.

§read_only: Option<bool>

Read only property will be only sent in read requests like GET.

§xml: Option<Xml>

Additional Xml formatting of the Object.

§multiple_of: Option<Number>

Must be a number strictly greater than 0. Numeric value is considered valid if value divided by the multiple_of value results an integer.

§maximum: Option<Number>

Specify inclusive upper limit for the Object’s value. Number is considered valid if it is equal or less than the maximum.

§minimum: Option<Number>

Specify inclusive lower limit for the Object’s value. Number value is considered valid if it is equal or greater than the minimum.

§exclusive_maximum: Option<Number>

Specify exclusive upper limit for the Object’s value. Number value is considered valid if it is strictly less than exclusive_maximum.

§exclusive_minimum: Option<Number>

Specify exclusive lower limit for the Object’s value. Number value is considered valid if it is strictly above the exclusive_minimum.

§max_length: Option<usize>

Specify maximum length for string values. max_length cannot be a negative integer value. Value is considered valid if content length is equal or less than the max_length.

§min_length: Option<usize>

Specify minimum length for string values. min_length cannot be a negative integer value. Setting this to 0 has the same effect as omitting this field. Value is considered valid if content length is equal or more than the min_length.

§pattern: Option<String>

Define a valid ECMA-262 dialect regular expression. The string content is considered valid if the pattern matches the value successfully.

§max_properties: Option<usize>

Specify inclusive maximum amount of properties an Object can hold.

§min_properties: Option<usize>

Specify inclusive minimum amount of properties an Object can hold. Setting this to 0 will have same effect as omitting the attribute.

§extensions: Option<Extensions>

Optional extensions x-something.

§content_encoding: String

The content_encoding keyword specifies the encoding used to store the contents, as specified in RFC 2054, part 6.1 and [RFC 4648](RFC 2054, part 6.1).

Typically this is either unset for string content types which then uses the content encoding of the underlying JSON document. If the content is in binary format such as an image or an audio set it to base64 to encode it as Base64.

See more details at https://json-schema.org/understanding-json-schema/reference/non_json_data#contentencoding

§content_media_type: String

The content_media_type keyword specifies the MIME type of the contents of a string, as described in RFC 2046.

See more details at https://json-schema.org/understanding-json-schema/reference/non_json_data#contentmediatype

Implementations§

Source§

impl Object

Source

pub fn builder() -> ObjectBuilder

Construct a new ObjectBuilder.

This is effectively same as calling ObjectBuilder::new

Source§

impl Object

Source

pub fn new() -> Self

Initialize a new Object with default SchemaType. This effectively same as calling Object::with_type(SchemaType::Object).

Source

pub fn with_type<T: Into<SchemaType>>(schema_type: T) -> Self

Initialize new Object with given SchemaType.

Create std::string object type which can be used to define string field of an object.

let object = Object::with_type(Type::String);

Trait Implementations§

Source§

impl Clone for Object

Source§

fn clone(&self) -> Object

Returns a copy 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 Default for Object

Source§

fn default() -> Object

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

impl<'de> Deserialize<'de> for Object

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 From<Object> for ArrayItems

Source§

fn from(value: Object) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for ObjectBuilder

Source§

fn from(value: Object) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for RefOr<Schema>

Source§

fn from(object: Object) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for Schema

Source§

fn from(s: Object) -> Self

Converts to this type from the input type.
Source§

impl From<ObjectBuilder> for Object

Source§

fn from(value: ObjectBuilder) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Object

Source§

fn eq(&self, other: &Object) -> 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 Object

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 ToArray for Object

Source§

fn to_array(self) -> Array

Wrap this RefOr<Schema> with Array.
Source§

impl StructuralPartialEq for Object

Auto Trait Implementations§

§

impl Freeze for Object

§

impl RefUnwindSafe for Object

§

impl Send for Object

§

impl Sync for Object

§

impl Unpin for Object

§

impl UnwindSafe for Object

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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>,