pub trait SchemaSerialize: ToSchema {
// Required methods
fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer;
fn is_present(&self) -> bool;
}Expand description
A type that is serializable according to its schema specification.
This trait is similar to serde’s Serialize, but allows
- “automatic”, type-based optional properties, which prevents littering your codebase with
#[serde(skip_serializing_if="...")] - deviating from the default or third-party serde implementations (e.g. for the time crate)
Required Methods§
Sourcefn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serializes an object of this type.
Users of this trait should only call this method if is_present is
true and implementations should return an error in this case.
Sourcefn is_present(&self) -> bool
fn is_present(&self) -> bool
Determines whether a property of this type should be serialized within a JSON object.
If false is returned for a property value, it is not serialized (i.e. omitted from the
JSON object).
Therefore, if <Self as ToSchema>::REQUIRED == true, this method must never return
false, otherwise the schema will be violated in these cases.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.