diff --git a/openapi/src/main.rs b/openapi/src/main.rs index 3f217f36..aea1a408 100644 --- a/openapi/src/main.rs +++ b/openapi/src/main.rs @@ -316,6 +316,9 @@ fn gen_impl_object(meta: &Metadata, object: &str) -> String { if let Some(doc) = schema["properties"]["id"]["description"].as_str() { print_doc_comment(&mut out, doc, 1); } + if id_type == "InvoiceId" { + out.push_str(" #[serde(default = \"InvoiceId::empty\")]"); + } out.push_str(" pub id: "); out.push_str(&id_type); out.push_str(",\n"); diff --git a/src/ids.rs b/src/ids.rs index 9a33b1b5..26f3a034 100644 --- a/src/ids.rs +++ b/src/ids.rs @@ -528,6 +528,12 @@ def_id!(TransferId, "tr_"); def_id!(TransferReversalId, "trr_"); def_id!(WebhookEndpointId, "we_"); +impl InvoiceId { + pub(crate) fn empty() -> Self { + Self("".into()) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/resources/invoice.rs b/src/resources/invoice.rs index 28fc7e55..4205d87d 100644 --- a/src/resources/invoice.rs +++ b/src/resources/invoice.rs @@ -17,6 +17,7 @@ use serde_derive::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Invoice { /// Unique identifier for the object. + #[serde(default = "InvoiceId::empty")] pub id: InvoiceId, /// The country of the business associated with this invoice, most often the business creating the invoice.