Skip to main content

Responses

Struct Responses 

Source
pub struct Responses {
    pub default_response: Option<RefOr<Response>>,
    pub responses: Map<RefOr<Response>>,
    pub extensions: Extensions,
}
Expand description

The responses an operation may return.

Serializes with default_response under the default key, each entry of responses under its status pattern, and extensions alongside them.

Fields§

§default_response: Option<RefOr<Response>>

The response used for status codes not otherwise covered.

§responses: Map<RefOr<Response>>

Responses keyed by status code or wildcard.

§extensions: Extensions

Specification extensions.

Implementations§

Source§

impl Responses

Source

pub fn new() -> Self

Creates an empty set of responses.

A description must not keep it empty: the specification requires at least one response, and crate::validate reports the omission.

Source

pub fn with(self, status: u16, response: Response) -> Self

Declares a response for an exact status code.

Source

pub fn with_pattern( self, pattern: StatusPattern, response: RefOr<Response>, ) -> Self

Declares a response for a status pattern.

Source

pub fn with_default(self, response: Response) -> Self

Sets the fallback response.

Source

pub fn is_empty(&self) -> bool

Returns true when nothing at all is declared.

Extensions count. Operation.responses is skipped when this is true, so ignoring them would silently drop a Responses that carries only x- fields — which is exactly the drop a round trip must not make.

This is therefore not the question the specification’s “MUST contain at least one response code” asks. declares_a_response is.

Source

pub fn declares_a_response(&self) -> bool

Returns true when a status code or default is declared.

The distinction from is_empty is the whole point: an extension is not a response, so a Responses Object carrying only x- fields is not empty and still declares nothing.

Source

pub fn get(&self, status: u16) -> Option<&RefOr<Response>>

Looks up the response declared for an exact status code.

Only exact keys are considered; wildcard resolution is a consumer concern and depends on precedence rules this method does not apply.

Source

pub fn merge_from(&mut self, other: &Self)

Merges another set into this one, keeping existing entries on conflict.

This is how an interceptor’s declared responses join an operation’s own.

Source

pub fn union_from(&mut self, other: &Self)

Merges another set into this one, unioning two problem responses that meet on one status.

merge_from with one exception, and the exception is the only reason this exists. A status is one key and a response is what a client is told about it, so where two contributors both name a status — an extractor’s rejection and the handler’s error type is the case that motivates this — keeping whichever arrived first publishes half of what the operation can send.

The exception is deliberately narrow. It applies where both entries declare an application/problem+json schema, because two problem documents under one status are two branches of a choice over the same component — which merging two arbitrary responses is not. Anything else keeps the entry already declared, exactly as merge_from would.

§What the union is

The entry already declared, with two of its fields replaced, so everything else it carries — a WWW-Authenticate header, a link, an extension — survives a contributor arriving after it.

  • The schema. A narrowed problem schema constrains type to a const on every branch, which is the shape #[derive(ApiError)] emits: one allOf for a single type, a oneOf of them for several. Where both sides are narrowed the branches are flattened, deduplicated by the URI they publish and rebuilt — a single allOf where one survives, a oneOf where several do. The dedup is what keeps oneOf sound: two branches repeating a const are satisfied at once, which is exactly what the keyword forbids.

    Where one side instead admits everything — true, or a bare $ref to the shared component, which every problem document satisfies — that side is the union: it already admits every document the other describes, and narrowing to the other would declare less than the operation sends.

    A side that is neither is not read as either. A schema satisfied by nothing, an empty oneOf, and a oneOf whose branches overlap all fail the narrowing read while admitting strictly less than a narrowed side, so adopting one would declare a schema the operation’s own bodies fail. Those keep the entry already declared, as merge_from would.

  • The description. Both, joined with "; ", dropping a sentence already written word for word. Prose is under no exactly-one rule, so a status two contributors reach says what each of them means.

Trait Implementations§

Source§

impl Clone for Responses

Source§

fn clone(&self) -> Self

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 Responses

Source§

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

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

impl Default for Responses

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Responses

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Responses

Source§

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

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Responses

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.