Skip to main content

Content

Struct Content 

Source
#[non_exhaustive]
pub struct Content { pub ref_location: Option<String>, pub schema: Option<RefOr<Schema>>, pub item_schema: Option<RefOr<Schema>>, pub example: Option<Value>, pub examples: PropMap<String, RefOr<Example>>, pub encoding: PropMap<String, Encoding>, pub prefix_encoding: Vec<Encoding>, pub item_encoding: Option<Encoding>, pub extensions: PropMap<String, Value>, }
Expand description

Content holds request body content or response content.

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.
§ref_location: Option<String>

Reference to a reusable Media Type Object, e.g. one defined under components.mediaTypes. Added in OpenAPI 3.2.

content maps are typed as Content rather than RefOr<Content> so that existing callers keep compiling; a Content carrying only this field serializes exactly as a Reference Object. As with any Reference Object, sibling fields are ignored by consumers.

let content = Content::from_ref("#/components/mediaTypes/FramePayload");
§schema: Option<RefOr<Schema>>

Schema used in response body or request body.

§item_schema: Option<RefOr<Schema>>

Schema describing each item within a sequential media type, e.g. text/event-stream or application/jsonl. Added in OpenAPI 3.2.

Unlike Content::schema, which applies to the complete content, item_schema applies to each item in the stream independently. Both may be used together.

See https://spec.openapis.org/oas/v3.2.0.html#media-type-object.

§example: Option<Value>

Example for request body or response body.

§examples: PropMap<String, RefOr<Example>>

Examples of the request body or response body. Content::examples should match to media type and specified schema if present. Content::examples and Content::example are mutually exclusive. If both are defined examples will override value in example.

§encoding: PropMap<String, Encoding>

A map between a property name and its encoding information.

The key, being the property name, MUST exist in the Content::schema as a property, with schema being a Schema::Object and this object containing the same property key in Object::properties.

The encoding object SHALL only apply to request_body objects when the media type is multipart or application/x-www-form-urlencoded.

Must not be combined with Content::prefix_encoding or Content::item_encoding.

§prefix_encoding: Vec<Encoding>

Positional encoding information, applied to the array item at the same index. Added in OpenAPI 3.2 and only applicable to multipart media types.

Requires either Content::item_schema or an array Content::schema to be present, and must not be combined with Content::encoding.

§item_encoding: Option<Encoding>

A single encoding applied to all array items not covered by Content::prefix_encoding. Added in OpenAPI 3.2 and only applicable to multipart media types.

Requires either Content::item_schema or an array Content::schema to be present, and must not be combined with Content::encoding.

§extensions: PropMap<String, Value>

Optional extensions “x-something”

Implementations§

Source§

impl Content

Source

pub fn new<I: Into<RefOr<Schema>>>(schema: I) -> Self

Construct a new Content.

Source

pub fn from_ref<S: Into<String>>(ref_location: S) -> Self

Construct a Content that is purely a reference to a reusable Media Type Object. Requires OpenAPI 3.2.

Source

pub fn ref_location<S: Into<String>>(self, ref_location: S) -> Self

Set the $ref location for this Content and return self. Requires OpenAPI 3.2.

Source

pub fn schema<I: Into<RefOr<Schema>>>(self, component: I) -> Self

Add schema.

Source

pub fn item_schema<I: Into<RefOr<Schema>>>(self, component: I) -> Self

Add the schema describing each item of a sequential media type. See Content::item_schema. Requires OpenAPI 3.2.

Source

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

Add example of schema.

Source

pub fn extend_examples<E: IntoIterator<Item = (N, V)>, N: Into<String>, V: Into<RefOr<Example>>>( self, examples: E, ) -> Self

Add iterator of (N, V) where N is name of example and V is Example to Content of a request body or response body.

Content::examples and Content::example are mutually exclusive. If both are defined examples will override value in example.

Source

pub fn extensions(self, extensions: PropMap<String, Value>) -> Self

Add openapi extensions (x-something) for Content.

Source

pub fn encoding<S: Into<String>, E: Into<Encoding>>( self, property_name: S, encoding: E, ) -> Self

Add an encoding.

The property_name MUST exist in the Content::schema as a property, with schema being a Schema::Object and this object containing the same property key in Object::properties.

The encoding object SHALL only apply to request_body objects when the media type is multipart or application/x-www-form-urlencoded.

Source

pub fn prefix_encoding<I: IntoIterator<Item = Encoding>>( self, prefix_encoding: I, ) -> Self

Set the positional encodings. See Content::prefix_encoding. Requires OpenAPI 3.2.

Source

pub fn item_encoding<E: Into<Encoding>>(self, item_encoding: E) -> Self

Set the encoding applied to remaining array items. See Content::item_encoding. Requires OpenAPI 3.2.

Trait Implementations§

Source§

impl Clone for Content

Source§

fn clone(&self) -> Content

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 Content

Source§

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

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

impl Default for Content

Source§

fn default() -> Content

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

impl<'de> Deserialize<'de> for Content

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<RefOr<Schema>> for Content

Source§

fn from(schema: RefOr<Schema>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Content

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Content

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 Content

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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