openapi-to-rust 0.17.0

Generate typed Rust models, HTTP/SSE clients, and Axum servers from OpenAPI 3.0/3.1 (experimental 3.2)
Documentation
---
source: src/test_helpers.rs
expression: "&generated_code"
---
//! Generated types from OpenAPI specification
//!
//! This file contains all the generated types for the API.
//! Do not edit manually - regenerate using the appropriate script.
#![allow(clippy::large_enum_variant)]
#![allow(clippy::format_in_format_args)]
#![allow(clippy::let_unit_value)]
#![allow(unreachable_patterns)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RequestToolResultBlock {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<RequestToolResultBlockContent>,
    ///Constraint: pattern=`^[a-zA-Z0-9_-]+$`
    pub tool_use_id: String,
}
#[derive(Debug, Clone)]
pub enum RequestToolResultBlockContentItemUnion {
    RequestTextBlock(RequestTextBlock),
    RequestImageBlock(RequestImageBlock),
}
impl serde::Serialize for RequestToolResultBlockContentItemUnion {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        match self {
            Self::RequestTextBlock(payload) => {
                let mut value = serde_json::to_value(payload)
                    .map_err(serde::ser::Error::custom)?;
                let object = value
                    .as_object_mut()
                    .ok_or_else(|| {
                        serde::ser::Error::custom(
                            concat!(
                                "discriminated union variant `",
                                stringify!(RequestTextBlock),
                                "` did not serialize as an object",
                            ),
                        )
                    })?;
                match object.get("type") {
                    Some(
                        serde_json::Value::String(tag),
                    ) if matches!(tag.as_str(), "text") => {}
                    Some(serde_json::Value::String(tag)) => {
                        return Err(
                            serde::ser::Error::custom(
                                format!(
                                    "discriminator `{}` value `{tag}` is not valid for variant `{}`",
                                    "type", stringify!(RequestTextBlock),
                                ),
                            ),
                        );
                    }
                    Some(_) => {
                        return Err(
                            serde::ser::Error::custom(
                                concat!(
                                    "discriminator `", "type",
                                    "` did not serialize as a string",
                                ),
                            ),
                        );
                    }
                    None => {
                        object
                            .insert(
                                "type".to_string(),
                                serde_json::Value::String("text".to_string()),
                            );
                    }
                }
                value.serialize(serializer)
            }
            Self::RequestImageBlock(payload) => {
                let mut value = serde_json::to_value(payload)
                    .map_err(serde::ser::Error::custom)?;
                let object = value
                    .as_object_mut()
                    .ok_or_else(|| {
                        serde::ser::Error::custom(
                            concat!(
                                "discriminated union variant `",
                                stringify!(RequestImageBlock),
                                "` did not serialize as an object",
                            ),
                        )
                    })?;
                match object.get("type") {
                    Some(
                        serde_json::Value::String(tag),
                    ) if matches!(tag.as_str(), "image") => {}
                    Some(serde_json::Value::String(tag)) => {
                        return Err(
                            serde::ser::Error::custom(
                                format!(
                                    "discriminator `{}` value `{tag}` is not valid for variant `{}`",
                                    "type", stringify!(RequestImageBlock),
                                ),
                            ),
                        );
                    }
                    Some(_) => {
                        return Err(
                            serde::ser::Error::custom(
                                concat!(
                                    "discriminator `", "type",
                                    "` did not serialize as a string",
                                ),
                            ),
                        );
                    }
                    None => {
                        object
                            .insert(
                                "type".to_string(),
                                serde_json::Value::String("image".to_string()),
                            );
                    }
                }
                value.serialize(serializer)
            }
        }
    }
}
impl<'de> serde::Deserialize<'de> for RequestToolResultBlockContentItemUnion {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let value = serde_json::Value::deserialize(deserializer)?;
        let discriminator = match value.get("type") {
            Some(serde_json::Value::String(discriminator)) => {
                Some(discriminator.as_str())
            }
            Some(_) => {
                return Err(
                    serde::de::Error::custom(
                        concat!("non-string discriminator `", "type", "`",),
                    ),
                );
            }
            None => None,
        };
        match discriminator {
            Some(discriminator) => {
                match discriminator {
                    "text" => {
                        let primary_error = match serde_json::from_value::<
                            RequestTextBlock,
                        >(value.clone()) {
                            Ok(payload) => return Ok(Self::RequestTextBlock(payload)),
                            Err(error) => error,
                        };
                        let mut structural_match: Option<(Self, &'static str)> = None;
                        if let Ok(payload) = serde_json::from_value::<
                            RequestImageBlock,
                        >(value.clone()) {
                            if let Some((_, first_name)) = &structural_match {
                                return Err(
                                    serde::de::Error::custom(
                                        format!(
                                            "discriminator `{}` value `{}` did not fit its mapped branch and structurally matched both `{}` and `{}`",
                                            "type", "text", first_name, stringify!(RequestImageBlock),
                                        ),
                                    ),
                                );
                            }
                            structural_match = Some((
                                Self::RequestImageBlock(payload),
                                stringify!(RequestImageBlock),
                            ));
                        }
                        match structural_match {
                            Some((payload, _)) => Ok(payload),
                            None => Err(serde::de::Error::custom(primary_error)),
                        }
                    }
                    "image" => {
                        let primary_error = match serde_json::from_value::<
                            RequestImageBlock,
                        >(value.clone()) {
                            Ok(payload) => return Ok(Self::RequestImageBlock(payload)),
                            Err(error) => error,
                        };
                        let mut structural_match: Option<(Self, &'static str)> = None;
                        if let Ok(payload) = serde_json::from_value::<
                            RequestTextBlock,
                        >(value.clone()) {
                            if let Some((_, first_name)) = &structural_match {
                                return Err(
                                    serde::de::Error::custom(
                                        format!(
                                            "discriminator `{}` value `{}` did not fit its mapped branch and structurally matched both `{}` and `{}`",
                                            "type", "image", first_name, stringify!(RequestTextBlock),
                                        ),
                                    ),
                                );
                            }
                            structural_match = Some((
                                Self::RequestTextBlock(payload),
                                stringify!(RequestTextBlock),
                            ));
                        }
                        match structural_match {
                            Some((payload, _)) => Ok(payload),
                            None => Err(serde::de::Error::custom(primary_error)),
                        }
                    }
                    other => {
                        Err(
                            serde::de::Error::custom(
                                format!(
                                    "unknown discriminator value `{other}` for `{}`", "type",
                                ),
                            ),
                        )
                    }
                }
            }
            None => {
                Err(
                    serde::de::Error::custom(
                        concat!("missing string discriminator `", "type", "`",),
                    ),
                )
            }
        }
    }
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RequestTextBlock {
    pub text: String,
    pub r#type: serde_json::Value,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum RequestToolResultBlockContent {
    String(String),
    RequestToolResultBlockContentArray(RequestToolResultBlockContentArray),
}
///Array variant in union
pub type RequestToolResultBlockContentArray = Vec<
    RequestToolResultBlockContentItemUnion,
>;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RequestImageBlock {
    pub source: RequestImageBlockSource,
    pub r#type: serde_json::Value,
}
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct RequestImageBlockSource {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum MessageContent {
    String(String),
    MessageContentStringArray(MessageContentStringArray),
    MessageContentItemArray(MessageContentItemArray),
}
///Array variant in union
pub type MessageContentItemArray = Vec<MessageContentItem>;
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct MessageContentItem {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,
}
///Array variant in union
pub type MessageContentStringArray = Vec<String>;