pub struct Example {
pub summary: Option<String>,
pub description: Option<String>,
pub extensions: Extensions,
/* private fields */
}Expand description
A worked example of a parameter, request body, response body or header.
§Choosing a value field
OpenAPI 3.1 offers value and externalValue, which are mutually
exclusive.
3.2 adds dataValue and serializedValue, and deprecates value for
non-JSON serialization targets — for those, value has
implementation-defined behaviour, which is exactly the kind of ambiguity
Kynos avoids. Prefer data (the example as data, before
serialization) and serialized (the example as it
appears on the wire) whenever openapi32 is available and the target is not
JSON.
The exclusions between those four fields are not a plain one-of, which is
why they live in ExampleValue rather than in four Options.
Fields§
§summary: Option<String>A short description of the example.
description: Option<String>A long description of the example. CommonMark syntax may be used.
extensions: ExtensionsSpecification extensions.
Implementations§
Source§impl Example
impl Example
Sourcepub fn external(uri: impl Into<String>) -> Self
pub fn external(uri: impl Into<String>) -> Self
Creates an example pointing at an external payload.
Sourcepub fn data(data: impl Into<Value>) -> Self
pub fn data(data: impl Into<Value>) -> Self
Creates an example given as data, before serialization.
Preferred over new whenever the serialization target
is not JSON.
Sourcepub fn serialized(serialized: impl Into<String>) -> Self
pub fn serialized(serialized: impl Into<String>) -> Self
Creates an example given only in its serialized form.
Sourcepub fn data_serialized(
data: impl Into<Value>,
serialized: impl Into<String>,
) -> Self
pub fn data_serialized( data: impl Into<Value>, serialized: impl Into<String>, ) -> Self
Creates an example given as data together with its serialization.
The pair a boolean query parameter needs: true is the data, flag=true
is what goes on the wire, and neither implies the other.
Sourcepub fn data_external(data: impl Into<Value>, uri: impl Into<String>) -> Self
pub fn data_external(data: impl Into<Value>, uri: impl Into<String>) -> Self
Creates an example given as data, serialized into an external payload.
Sourcepub fn value(&self) -> Option<&ExampleValue>
pub fn value(&self) -> Option<&ExampleValue>
The example this object carries, if it carries one.
An Example Object with only a summary is valid, if not useful.
Sourcepub fn with_summary(self, summary: impl Into<String>) -> Self
pub fn with_summary(self, summary: impl Into<String>) -> Self
Sets the short summary.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Sets the long description.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Example
impl<'de> Deserialize<'de> for Example
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Example
impl StructuralPartialEq for Example
Auto Trait Implementations§
impl Freeze for Example
impl RefUnwindSafe for Example
impl Send for Example
impl Sync for Example
impl Unpin for Example
impl UnsafeUnpin for Example
impl UnwindSafe for Example
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.