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.