Skip to main content

MergePropertiesIntoOneOf

Struct MergePropertiesIntoOneOf 

Source
pub struct MergePropertiesIntoOneOf;
Expand description

A schemars Transform that merges top-level properties and required fields from a wrapper struct into each oneOf variant.

This is used when a struct wraps a #[serde(flatten)] tagged enum: schemars places the struct’s own fields as top-level properties alongside the enum’s oneOf. OpenAPI code generators don’t handle this combination, so this transform pushes the shared properties into each variant so they appear in the generated models.

§Usage

#[derive(schemars::JsonSchema, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[schemars(transform = MergePropertiesIntoOneOf)]
struct Wrapper {
    sequence_number: u64,
    timestamp: DateTime<Utc>,
    #[serde(flatten)]
    kind: MyEnum,
}

Trait Implementations§

Source§

impl Transform for MergePropertiesIntoOneOf

Source§

fn transform(&mut self, schema: &mut Schema)

Applies the transform to the given Schema. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Erased for T