---
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 ImageBlock {
pub source: ImageBlockSource,
pub r#type: ImageBlockType,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct URLImageSource {
pub r#type: URLImageSourceType,
pub url: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
pub enum URLImageSourceType {
#[default]
#[serde(rename = "url")]
Url,
}
impl URLImageSourceType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Url => "url",
}
}
}
impl ::std::fmt::Display for URLImageSourceType {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for URLImageSourceType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
pub enum ImageBlockType {
#[default]
#[serde(rename = "image")]
Image,
}
impl ImageBlockType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Image => "image",
}
}
}
impl ::std::fmt::Display for ImageBlockType {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for ImageBlockType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
#[derive(Debug, Clone)]
pub enum ImageBlockSource {
Base64ImageSource(Base64ImageSource),
URLImageSource(URLImageSource),
}
impl serde::Serialize for ImageBlockSource {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
Self::Base64ImageSource(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!(Base64ImageSource),
"` did not serialize as an object",
),
)
})?;
match object.get("type") {
Some(
serde_json::Value::String(tag),
) if matches!(tag.as_str(), "base64") => {}
Some(serde_json::Value::String(tag)) => {
return Err(
serde::ser::Error::custom(
format!(
"discriminator `{}` value `{tag}` is not valid for variant `{}`",
"type", stringify!(Base64ImageSource),
),
),
);
}
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("base64".to_string()),
);
}
}
value.serialize(serializer)
}
Self::URLImageSource(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!(URLImageSource),
"` did not serialize as an object",
),
)
})?;
match object.get("type") {
Some(
serde_json::Value::String(tag),
) if matches!(tag.as_str(), "url") => {}
Some(serde_json::Value::String(tag)) => {
return Err(
serde::ser::Error::custom(
format!(
"discriminator `{}` value `{tag}` is not valid for variant `{}`",
"type", stringify!(URLImageSource),
),
),
);
}
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("url".to_string()),
);
}
}
value.serialize(serializer)
}
}
}
}
impl<'de> serde::Deserialize<'de> for ImageBlockSource {
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 {
"base64" => {
let primary_error = match serde_json::from_value::<
Base64ImageSource,
>(value.clone()) {
Ok(payload) => return Ok(Self::Base64ImageSource(payload)),
Err(error) => error,
};
let mut structural_match: Option<(Self, &'static str)> = None;
if let Ok(payload) = serde_json::from_value::<
URLImageSource,
>(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", "base64", first_name, stringify!(URLImageSource),
),
),
);
}
structural_match = Some((
Self::URLImageSource(payload),
stringify!(URLImageSource),
));
}
match structural_match {
Some((payload, _)) => Ok(payload),
None => Err(serde::de::Error::custom(primary_error)),
}
}
"url" => {
let primary_error = match serde_json::from_value::<
URLImageSource,
>(value.clone()) {
Ok(payload) => return Ok(Self::URLImageSource(payload)),
Err(error) => error,
};
let mut structural_match: Option<(Self, &'static str)> = None;
if let Ok(payload) = serde_json::from_value::<
Base64ImageSource,
>(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", "url", first_name, stringify!(Base64ImageSource),
),
),
);
}
structural_match = Some((
Self::Base64ImageSource(payload),
stringify!(Base64ImageSource),
));
}
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 Base64ImageSource {
pub data: String,
pub r#type: Base64ImageSourceType,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
pub enum Base64ImageSourceType {
#[default]
#[serde(rename = "base64")]
Base64,
}
impl Base64ImageSourceType {
pub fn as_str(&self) -> &'static str {
match self {
Self::Base64 => "base64",
}
}
}
impl ::std::fmt::Display for Base64ImageSourceType {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.write_str(self.as_str())
}
}
impl AsRef<str> for Base64ImageSourceType {
fn as_ref(&self) -> &str {
self.as_str()
}
}