From fecaa2e17b4fb443e44b1f470beddd6659eeb107 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Wed, 1 Feb 2023 09:19:03 +0000 Subject: [PATCH] feat: improve api doc code to fix / add more coverage --- openapi/src/url_finder.rs | 33 ++++++++++++++----- src/resources/generated/balance.rs | 2 ++ src/resources/generated/capability.rs | 2 ++ src/resources/generated/cash_balance.rs | 2 ++ src/resources/generated/checkout_session.rs | 2 ++ .../generated/credit_note_line_item.rs | 2 ++ .../customer_cash_balance_transaction.rs | 2 ++ .../financial_connections_account.rs | 2 ++ .../financial_connections_session.rs | 2 ++ .../generated/identity_verification_report.rs | 2 ++ .../identity_verification_session.rs | 2 ++ .../generated/issuing_authorization.rs | 2 ++ src/resources/generated/issuing_card.rs | 2 ++ src/resources/generated/issuing_cardholder.rs | 2 ++ src/resources/generated/issuing_dispute.rs | 2 ++ .../generated/issuing_transaction.rs | 2 ++ src/resources/generated/login_link.rs | 2 ++ src/resources/generated/payment_link.rs | 2 +- src/resources/generated/radar_value_list.rs | 2 ++ .../generated/radar_value_list_item.rs | 2 ++ .../generated/reporting_report_run.rs | 2 ++ .../generated/reporting_report_type.rs | 2 ++ src/resources/generated/review.rs | 2 +- .../generated/scheduled_query_run.rs | 2 ++ src/resources/generated/tax_id.rs | 2 ++ .../generated/terminal_configuration.rs | 2 ++ .../generated/terminal_connection_token.rs | 2 ++ src/resources/generated/terminal_location.rs | 2 ++ src/resources/generated/terminal_reader.rs | 2 ++ 29 files changed, 78 insertions(+), 11 deletions(-) diff --git a/openapi/src/url_finder.rs b/openapi/src/url_finder.rs index e17b430d9..a6f902424 100644 --- a/openapi/src/url_finder.rs +++ b/openapi/src/url_finder.rs @@ -7,7 +7,7 @@ const APP_USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWeb #[derive(Debug)] pub struct UrlFinder { - html: String, + flattened_api_sections: serde_json::Map, } impl UrlFinder { @@ -17,8 +17,16 @@ impl UrlFinder { if resp.status().is_success() { let text = resp.text()?; - if text.contains("title: 'Stripe API Reference'") { - Ok(Self { html: text }) + if let Some(line) = text.lines().find(|l| l.contains("flattenedAPISections: {")) { + println!("{}", line); + Ok(Self { + flattened_api_sections: serde_json::from_str( + line.trim() + .trim_start_matches("flattenedAPISections: ") + .trim_end_matches(","), + ) + .expect("should be valid json"), + }) } else { Err(anyhow!("stripe api returned unexpected document")) } @@ -30,12 +38,19 @@ impl UrlFinder { pub fn url_for_object(&self, object: &str) -> Option { let object_name = object.replace('.', "_").to_snake_case(); - let doc_url = format!("/{}s/object", object_name); - if self.html.contains(&doc_url) { - Some(format!("https://stripe.com/docs/api{}", doc_url)) - } else { - log::warn!("{} not in html", doc_url); - None + let object_names = [format!("{}_object", object_name), object_name]; + for name in object_names { + if let Some(path) = self + .flattened_api_sections + .get(&name) + .and_then(|o| o.as_object().expect("this should be an object").get("path")) + .and_then(|s| s.as_str()) + { + return Some(format!("https://stripe.com/docs/api{}", path)); + } } + + log::warn!("{} not in html", object); + None } } diff --git a/src/resources/generated/balance.rs b/src/resources/generated/balance.rs index 4ac28dc56..dc397b976 100644 --- a/src/resources/generated/balance.rs +++ b/src/resources/generated/balance.rs @@ -10,6 +10,8 @@ use crate::params::{Expand, List, Object, RangeQuery, Timestamp}; use crate::resources::Currency; /// The resource representing a Stripe "Balance". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Balance { /// Funds that are available to be transferred or paid out, whether automatically by Stripe or explicitly via the [Transfers API](https://stripe.com/docs/api#transfers) or [Payouts API](https://stripe.com/docs/api#payouts). diff --git a/src/resources/generated/capability.rs b/src/resources/generated/capability.rs index 351415412..d6dd069ab 100644 --- a/src/resources/generated/capability.rs +++ b/src/resources/generated/capability.rs @@ -8,6 +8,8 @@ use crate::resources::{Account}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "AccountCapability". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Capability { /// The identifier for the capability. diff --git a/src/resources/generated/cash_balance.rs b/src/resources/generated/cash_balance.rs index eaecee595..cb2203eb0 100644 --- a/src/resources/generated/cash_balance.rs +++ b/src/resources/generated/cash_balance.rs @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize}; use crate::params::Object; /// The resource representing a Stripe "cash_balance". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct CashBalance { /// A hash of all cash balances available to this customer. diff --git a/src/resources/generated/checkout_session.rs b/src/resources/generated/checkout_session.rs index 1dcb1c371..bb25162bc 100644 --- a/src/resources/generated/checkout_session.rs +++ b/src/resources/generated/checkout_session.rs @@ -14,6 +14,8 @@ use crate::resources::{ }; /// The resource representing a Stripe "Session". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct CheckoutSession { /// Unique identifier for the object. diff --git a/src/resources/generated/credit_note_line_item.rs b/src/resources/generated/credit_note_line_item.rs index 52af0d86e..4362434ee 100644 --- a/src/resources/generated/credit_note_line_item.rs +++ b/src/resources/generated/credit_note_line_item.rs @@ -8,6 +8,8 @@ use crate::resources::{Discount, TaxRate}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "CreditNoteLineItem". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct CreditNoteLineItem { /// Unique identifier for the object. diff --git a/src/resources/generated/customer_cash_balance_transaction.rs b/src/resources/generated/customer_cash_balance_transaction.rs index 6bce96d4c..cabc4f61b 100644 --- a/src/resources/generated/customer_cash_balance_transaction.rs +++ b/src/resources/generated/customer_cash_balance_transaction.rs @@ -8,6 +8,8 @@ use crate::resources::{Currency, Customer, PaymentIntent, Refund}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "CustomerCashBalanceTransaction". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct CustomerCashBalanceTransaction { /// Unique identifier for the object. diff --git a/src/resources/generated/financial_connections_account.rs b/src/resources/generated/financial_connections_account.rs index 91b075ed5..713fca3b1 100644 --- a/src/resources/generated/financial_connections_account.rs +++ b/src/resources/generated/financial_connections_account.rs @@ -8,6 +8,8 @@ use crate::resources::{BankConnectionsResourceAccountholder, FinancialConnection use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "BankConnectionsResourceLinkedAccount". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct FinancialConnectionsAccount { /// Unique identifier for the object. diff --git a/src/resources/generated/financial_connections_session.rs b/src/resources/generated/financial_connections_session.rs index 4de2565ce..b5417a91d 100644 --- a/src/resources/generated/financial_connections_session.rs +++ b/src/resources/generated/financial_connections_session.rs @@ -9,6 +9,8 @@ use crate::resources::{BankConnectionsResourceAccountholder, FinancialConnection use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "BankConnectionsResourceLinkAccountSession". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct FinancialConnectionsSession { /// Unique identifier for the object. diff --git a/src/resources/generated/identity_verification_report.rs b/src/resources/generated/identity_verification_report.rs index 5f90f1ce0..6aefaa96e 100644 --- a/src/resources/generated/identity_verification_report.rs +++ b/src/resources/generated/identity_verification_report.rs @@ -8,6 +8,8 @@ use crate::resources::{Address}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "GelatoVerificationReport". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IdentityVerificationReport { /// Unique identifier for the object. diff --git a/src/resources/generated/identity_verification_session.rs b/src/resources/generated/identity_verification_session.rs index e1e9250f9..e2ea88a39 100644 --- a/src/resources/generated/identity_verification_session.rs +++ b/src/resources/generated/identity_verification_session.rs @@ -8,6 +8,8 @@ use crate::resources::{Address, IdentityVerificationReport}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "GelatoVerificationSession". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IdentityVerificationSession { /// Unique identifier for the object. diff --git a/src/resources/generated/issuing_authorization.rs b/src/resources/generated/issuing_authorization.rs index d6962439b..bb506d301 100644 --- a/src/resources/generated/issuing_authorization.rs +++ b/src/resources/generated/issuing_authorization.rs @@ -13,6 +13,8 @@ use crate::resources::{ }; /// The resource representing a Stripe "IssuingAuthorization". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IssuingAuthorization { /// Unique identifier for the object. diff --git a/src/resources/generated/issuing_card.rs b/src/resources/generated/issuing_card.rs index e661c7b93..2e31a47b3 100644 --- a/src/resources/generated/issuing_card.rs +++ b/src/resources/generated/issuing_card.rs @@ -12,6 +12,8 @@ use crate::resources::{ }; /// The resource representing a Stripe "IssuingCard". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IssuingCard { /// Unique identifier for the object. diff --git a/src/resources/generated/issuing_cardholder.rs b/src/resources/generated/issuing_cardholder.rs index 173f104e7..1bbdd3945 100644 --- a/src/resources/generated/issuing_cardholder.rs +++ b/src/resources/generated/issuing_cardholder.rs @@ -9,6 +9,8 @@ use crate::params::{Expandable, Metadata, Object, Timestamp}; use crate::resources::{Address, Currency, File, MerchantCategory}; /// The resource representing a Stripe "IssuingCardholder". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IssuingCardholder { /// Unique identifier for the object. diff --git a/src/resources/generated/issuing_dispute.rs b/src/resources/generated/issuing_dispute.rs index 202964bb3..bcb619b77 100644 --- a/src/resources/generated/issuing_dispute.rs +++ b/src/resources/generated/issuing_dispute.rs @@ -11,6 +11,8 @@ use crate::resources::{ }; /// The resource representing a Stripe "IssuingDispute". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IssuingDispute { /// Unique identifier for the object. diff --git a/src/resources/generated/issuing_transaction.rs b/src/resources/generated/issuing_transaction.rs index b70d0914d..3e7f11eb5 100644 --- a/src/resources/generated/issuing_transaction.rs +++ b/src/resources/generated/issuing_transaction.rs @@ -12,6 +12,8 @@ use crate::resources::{ }; /// The resource representing a Stripe "IssuingTransaction". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct IssuingTransaction { /// Unique identifier for the object. diff --git a/src/resources/generated/login_link.rs b/src/resources/generated/login_link.rs index 0d4137c6c..33817dc92 100644 --- a/src/resources/generated/login_link.rs +++ b/src/resources/generated/login_link.rs @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize}; use crate::params::{Object, Timestamp}; /// The resource representing a Stripe "LoginLink". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct LoginLink { /// Time at which the object was created. diff --git a/src/resources/generated/payment_link.rs b/src/resources/generated/payment_link.rs index 943da23bc..84d804209 100644 --- a/src/resources/generated/payment_link.rs +++ b/src/resources/generated/payment_link.rs @@ -11,7 +11,7 @@ use crate::resources::{Account, CheckoutSessionItem, Currency, ShippingRate}; /// The resource representing a Stripe "PaymentLink". /// -/// For more details see +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct PaymentLink { /// Unique identifier for the object. diff --git a/src/resources/generated/radar_value_list.rs b/src/resources/generated/radar_value_list.rs index 26721a684..d5e5eb761 100644 --- a/src/resources/generated/radar_value_list.rs +++ b/src/resources/generated/radar_value_list.rs @@ -8,6 +8,8 @@ use crate::resources::{RadarValueListItem}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "RadarListList". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct RadarValueList { /// Unique identifier for the object. diff --git a/src/resources/generated/radar_value_list_item.rs b/src/resources/generated/radar_value_list_item.rs index f2505fda1..20fb78df1 100644 --- a/src/resources/generated/radar_value_list_item.rs +++ b/src/resources/generated/radar_value_list_item.rs @@ -7,6 +7,8 @@ use crate::params::{Object, Timestamp}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "RadarListListItem". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct RadarValueListItem { /// Unique identifier for the object. diff --git a/src/resources/generated/reporting_report_run.rs b/src/resources/generated/reporting_report_run.rs index c8f42516e..4f5dbf3d9 100644 --- a/src/resources/generated/reporting_report_run.rs +++ b/src/resources/generated/reporting_report_run.rs @@ -8,6 +8,8 @@ use crate::resources::{Currency, File}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "reporting_report_run". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct ReportingReportRun { /// Unique identifier for the object. diff --git a/src/resources/generated/reporting_report_type.rs b/src/resources/generated/reporting_report_type.rs index fe58a042d..a66c875bc 100644 --- a/src/resources/generated/reporting_report_type.rs +++ b/src/resources/generated/reporting_report_type.rs @@ -7,6 +7,8 @@ use crate::params::{Object, Timestamp}; use serde::{Deserialize, Serialize}; /// The resource representing a Stripe "reporting_report_type". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct ReportingReportType { /// The [ID of the Report Type](https://stripe.com/docs/reporting/statements/api#available-report-types), such as `balance.summary.1`. diff --git a/src/resources/generated/review.rs b/src/resources/generated/review.rs index 2eb5faa7f..b69426c03 100644 --- a/src/resources/generated/review.rs +++ b/src/resources/generated/review.rs @@ -11,7 +11,7 @@ use crate::resources::{Charge, PaymentIntent, ReviewReason}; /// The resource representing a Stripe "RadarReview". /// -/// For more details see +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Review { /// Unique identifier for the object. diff --git a/src/resources/generated/scheduled_query_run.rs b/src/resources/generated/scheduled_query_run.rs index 68228688b..5e02d7ae5 100644 --- a/src/resources/generated/scheduled_query_run.rs +++ b/src/resources/generated/scheduled_query_run.rs @@ -9,6 +9,8 @@ use crate::params::{Object, Timestamp}; use crate::resources::File; /// The resource representing a Stripe "ScheduledQueryRun". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct ScheduledQueryRun { /// Unique identifier for the object. diff --git a/src/resources/generated/tax_id.rs b/src/resources/generated/tax_id.rs index 8a0aa9ba7..9737446fb 100644 --- a/src/resources/generated/tax_id.rs +++ b/src/resources/generated/tax_id.rs @@ -9,6 +9,8 @@ use crate::params::{Expandable, Object, Timestamp}; use crate::resources::Customer; /// The resource representing a Stripe "tax_id". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct TaxId { /// Unique identifier for the object. diff --git a/src/resources/generated/terminal_configuration.rs b/src/resources/generated/terminal_configuration.rs index 23dd7aafe..4d38d9a1f 100644 --- a/src/resources/generated/terminal_configuration.rs +++ b/src/resources/generated/terminal_configuration.rs @@ -9,6 +9,8 @@ use crate::params::{Expandable, Object}; use crate::resources::File; /// The resource representing a Stripe "TerminalConfigurationConfiguration". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct TerminalConfiguration { /// Unique identifier for the object. diff --git a/src/resources/generated/terminal_connection_token.rs b/src/resources/generated/terminal_connection_token.rs index 7886ed64b..e38051d1f 100644 --- a/src/resources/generated/terminal_connection_token.rs +++ b/src/resources/generated/terminal_connection_token.rs @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize}; use crate::params::Object; /// The resource representing a Stripe "TerminalConnectionToken". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct TerminalConnectionToken { /// The id of the location that this connection token is scoped to. diff --git a/src/resources/generated/terminal_location.rs b/src/resources/generated/terminal_location.rs index 6aff8e211..76d5d585d 100644 --- a/src/resources/generated/terminal_location.rs +++ b/src/resources/generated/terminal_location.rs @@ -9,6 +9,8 @@ use crate::params::{Metadata, Object}; use crate::resources::Address; /// The resource representing a Stripe "TerminalLocationLocation". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct TerminalLocation { /// Unique identifier for the object. diff --git a/src/resources/generated/terminal_reader.rs b/src/resources/generated/terminal_reader.rs index 4c8061d62..4362e19fd 100644 --- a/src/resources/generated/terminal_reader.rs +++ b/src/resources/generated/terminal_reader.rs @@ -9,6 +9,8 @@ use crate::params::{Expandable, Metadata, Object}; use crate::resources::{Currency, PaymentIntent, SetupIntent, TerminalLocation}; /// The resource representing a Stripe "TerminalReaderReader". +/// +/// For more details see #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct TerminalReader { /// Unique identifier for the object.