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: ExtensionsSpecification extensions.
Implementations§
Source§impl Responses
impl Responses
Sourcepub fn new() -> Self
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.
Sourcepub fn with(self, status: u16, response: Response) -> Self
pub fn with(self, status: u16, response: Response) -> Self
Declares a response for an exact status code.
Sourcepub fn with_pattern(
self,
pattern: StatusPattern,
response: RefOr<Response>,
) -> Self
pub fn with_pattern( self, pattern: StatusPattern, response: RefOr<Response>, ) -> Self
Declares a response for a status pattern.
Sourcepub fn with_default(self, response: Response) -> Self
pub fn with_default(self, response: Response) -> Self
Sets the fallback response.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn declares_a_response(&self) -> bool
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.
Sourcepub fn get(&self, status: u16) -> Option<&RefOr<Response>>
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.
Sourcepub fn merge_from(&mut self, other: &Self)
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.
Sourcepub fn union_from(&mut self, other: &Self)
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
typeto aconston every branch, which is the shape#[derive(ApiError)]emits: oneallOffor a single type, aoneOfof them for several. Where both sides are narrowed the branches are flattened, deduplicated by the URI they publish and rebuilt — a singleallOfwhere one survives, aoneOfwhere several do. The dedup is what keepsoneOfsound: two branches repeating aconstare satisfied at once, which is exactly what the keyword forbids.Where one side instead admits everything —
true, or a bare$refto 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 aoneOfwhose 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, asmerge_fromwould. -
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.