Skip to content

Commit

Permalink
Add object field for serialization without adding field
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 committed Apr 8, 2024
1 parent 4cc2678 commit 465c342
Show file tree
Hide file tree
Showing 151 changed files with 3,003 additions and 10,519 deletions.
94 changes: 19 additions & 75 deletions generated/stripe_billing/src/billing_portal_configuration/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// A portal configuration describes the functionality and behavior of a portal session.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct BillingPortalConfiguration {
/// Whether the configuration is active and can be used to create portal sessions.
pub active: bool,
Expand All @@ -25,8 +24,6 @@ pub struct BillingPortalConfiguration {
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
/// This can be useful for storing additional information about the object in a structured format.
pub metadata: Option<std::collections::HashMap<String, String>>,
/// String representing the object's type. Objects of the same type share the same value.
pub object: BillingPortalConfigurationObject,
/// Time at which the object was last updated. Measured in seconds since the Unix epoch.
pub updated: stripe_types::Timestamp,
}
Expand All @@ -43,7 +40,6 @@ pub struct BillingPortalConfigurationBuilder {
livemode: Option<bool>,
login_page: Option<stripe_billing::PortalLoginPage>,
metadata: Option<Option<std::collections::HashMap<String, String>>>,
object: Option<BillingPortalConfigurationObject>,
updated: Option<stripe_types::Timestamp>,
}

Expand Down Expand Up @@ -92,7 +88,6 @@ const _: () = {
"livemode" => Deserialize::begin(&mut self.livemode),
"login_page" => Deserialize::begin(&mut self.login_page),
"metadata" => Deserialize::begin(&mut self.metadata),
"object" => Deserialize::begin(&mut self.object),
"updated" => Deserialize::begin(&mut self.updated),

_ => <dyn Visitor>::ignore(),
Expand All @@ -112,7 +107,6 @@ const _: () = {
livemode: Deserialize::default(),
login_page: Deserialize::default(),
metadata: Deserialize::default(),
object: Deserialize::default(),
updated: Deserialize::default(),
}
}
Expand All @@ -130,7 +124,6 @@ const _: () = {
livemode: self.livemode?,
login_page: self.login_page.take()?,
metadata: self.metadata.take()?,
object: self.object?,
updated: self.updated?,
})
}
Expand Down Expand Up @@ -172,7 +165,6 @@ const _: () = {
"livemode" => b.livemode = Some(FromValueOpt::from_value(v)?),
"login_page" => b.login_page = Some(FromValueOpt::from_value(v)?),
"metadata" => b.metadata = Some(FromValueOpt::from_value(v)?),
"object" => b.object = Some(FromValueOpt::from_value(v)?),
"updated" => b.updated = Some(FromValueOpt::from_value(v)?),

_ => {}
Expand All @@ -182,74 +174,26 @@ const _: () = {
}
}
};
/// String representing the object's type. Objects of the same type share the same value.
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum BillingPortalConfigurationObject {
BillingPortalConfiguration,
}
impl BillingPortalConfigurationObject {
pub fn as_str(self) -> &'static str {
use BillingPortalConfigurationObject::*;
match self {
BillingPortalConfiguration => "billing_portal.configuration",
}
}
}

impl std::str::FromStr for BillingPortalConfigurationObject {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
use BillingPortalConfigurationObject::*;
match s {
"billing_portal.configuration" => Ok(BillingPortalConfiguration),
_ => Err(()),
}
}
}
impl std::fmt::Display for BillingPortalConfigurationObject {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}

impl std::fmt::Debug for BillingPortalConfigurationObject {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for BillingPortalConfigurationObject {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for BillingPortalConfigurationObject {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}

impl miniserde::de::Visitor for crate::Place<BillingPortalConfigurationObject> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out =
Some(BillingPortalConfigurationObject::from_str(s).map_err(|_| miniserde::Error)?);
Ok(())
}
}

stripe_types::impl_from_val_with_from_str!(BillingPortalConfigurationObject);
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for BillingPortalConfigurationObject {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::str::FromStr;
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
Self::from_str(&s).map_err(|_| {
serde::de::Error::custom("Unknown value for BillingPortalConfigurationObject")
})
impl serde::Serialize for BillingPortalConfiguration {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeStruct;
let mut s = s.serialize_struct("BillingPortalConfiguration", 13)?;
s.serialize_field("active", &self.active)?;
s.serialize_field("application", &self.application)?;
s.serialize_field("business_profile", &self.business_profile)?;
s.serialize_field("created", &self.created)?;
s.serialize_field("default_return_url", &self.default_return_url)?;
s.serialize_field("features", &self.features)?;
s.serialize_field("id", &self.id)?;
s.serialize_field("is_default", &self.is_default)?;
s.serialize_field("livemode", &self.livemode)?;
s.serialize_field("login_page", &self.login_page)?;
s.serialize_field("metadata", &self.metadata)?;
s.serialize_field("updated", &self.updated)?;

s.serialize_field("object", "billing_portal.configuration")?;
s.end()
}
}
impl stripe_types::Object for BillingPortalConfiguration {
Expand Down
88 changes: 16 additions & 72 deletions generated/stripe_billing/src/billing_portal_session/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/// Learn more in the [integration guide](https://stripe.com/docs/billing/subscriptions/integrating-customer-portal).
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct BillingPortalSession {
/// The configuration used by this session, describing the features available.
pub configuration: stripe_types::Expandable<stripe_billing::BillingPortalConfiguration>,
Expand All @@ -32,8 +31,6 @@ pub struct BillingPortalSession {
/// The IETF language tag of the locale Customer Portal is displayed in.
/// If blank or auto, the customer’s `preferred_locales` or browser’s locale is used.
pub locale: Option<stripe_billing::BillingPortalSessionLocale>,
/// String representing the object's type. Objects of the same type share the same value.
pub object: BillingPortalSessionObject,
/// The account for which the session was created on behalf of.
/// When specified, only subscriptions and invoices with this `on_behalf_of` account appear in the portal.
/// For more information, see the [docs](https://stripe.com/docs/connect/separate-charges-and-transfers#on-behalf-of).
Expand All @@ -53,7 +50,6 @@ pub struct BillingPortalSessionBuilder {
id: Option<stripe_billing::BillingPortalSessionId>,
livemode: Option<bool>,
locale: Option<Option<stripe_billing::BillingPortalSessionLocale>>,
object: Option<BillingPortalSessionObject>,
on_behalf_of: Option<Option<String>>,
return_url: Option<Option<String>>,
url: Option<String>,
Expand Down Expand Up @@ -100,7 +96,6 @@ const _: () = {
"id" => Deserialize::begin(&mut self.id),
"livemode" => Deserialize::begin(&mut self.livemode),
"locale" => Deserialize::begin(&mut self.locale),
"object" => Deserialize::begin(&mut self.object),
"on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
"return_url" => Deserialize::begin(&mut self.return_url),
"url" => Deserialize::begin(&mut self.url),
Expand All @@ -118,7 +113,6 @@ const _: () = {
id: Deserialize::default(),
livemode: Deserialize::default(),
locale: Deserialize::default(),
object: Deserialize::default(),
on_behalf_of: Deserialize::default(),
return_url: Deserialize::default(),
url: Deserialize::default(),
Expand All @@ -134,7 +128,6 @@ const _: () = {
id: self.id.take()?,
livemode: self.livemode?,
locale: self.locale?,
object: self.object?,
on_behalf_of: self.on_behalf_of.take()?,
return_url: self.return_url.take()?,
url: self.url.take()?,
Expand Down Expand Up @@ -172,7 +165,6 @@ const _: () = {
"id" => b.id = Some(FromValueOpt::from_value(v)?),
"livemode" => b.livemode = Some(FromValueOpt::from_value(v)?),
"locale" => b.locale = Some(FromValueOpt::from_value(v)?),
"object" => b.object = Some(FromValueOpt::from_value(v)?),
"on_behalf_of" => b.on_behalf_of = Some(FromValueOpt::from_value(v)?),
"return_url" => b.return_url = Some(FromValueOpt::from_value(v)?),
"url" => b.url = Some(FromValueOpt::from_value(v)?),
Expand All @@ -184,72 +176,24 @@ const _: () = {
}
}
};
/// String representing the object's type. Objects of the same type share the same value.
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum BillingPortalSessionObject {
BillingPortalSession,
}
impl BillingPortalSessionObject {
pub fn as_str(self) -> &'static str {
use BillingPortalSessionObject::*;
match self {
BillingPortalSession => "billing_portal.session",
}
}
}

impl std::str::FromStr for BillingPortalSessionObject {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
use BillingPortalSessionObject::*;
match s {
"billing_portal.session" => Ok(BillingPortalSession),
_ => Err(()),
}
}
}
impl std::fmt::Display for BillingPortalSessionObject {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}

impl std::fmt::Debug for BillingPortalSessionObject {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for BillingPortalSessionObject {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for BillingPortalSessionObject {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}
impl serde::Serialize for BillingPortalSession {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeStruct;
let mut s = s.serialize_struct("BillingPortalSession", 11)?;
s.serialize_field("configuration", &self.configuration)?;
s.serialize_field("created", &self.created)?;
s.serialize_field("customer", &self.customer)?;
s.serialize_field("flow", &self.flow)?;
s.serialize_field("id", &self.id)?;
s.serialize_field("livemode", &self.livemode)?;
s.serialize_field("locale", &self.locale)?;
s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
s.serialize_field("return_url", &self.return_url)?;
s.serialize_field("url", &self.url)?;

impl miniserde::de::Visitor for crate::Place<BillingPortalSessionObject> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out = Some(BillingPortalSessionObject::from_str(s).map_err(|_| miniserde::Error)?);
Ok(())
}
}

stripe_types::impl_from_val_with_from_str!(BillingPortalSessionObject);
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for BillingPortalSessionObject {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::str::FromStr;
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
Self::from_str(&s)
.map_err(|_| serde::de::Error::custom("Unknown value for BillingPortalSessionObject"))
s.serialize_field("object", "billing_portal.session")?;
s.end()
}
}
impl stripe_types::Object for BillingPortalSession {
Expand Down
Loading

0 comments on commit 465c342

Please sign in to comment.