Skip to content

Commit

Permalink
feat: improve api doc code to fix / add more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Feb 1, 2023
1 parent ae86ff4 commit fecaa2e
Show file tree
Hide file tree
Showing 29 changed files with 78 additions and 11 deletions.
33 changes: 24 additions & 9 deletions openapi/src/url_finder.rs
Expand Up @@ -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<String, serde_json::Value>,
}

impl UrlFinder {
Expand All @@ -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"))
}
Expand All @@ -30,12 +38,19 @@ impl UrlFinder {

pub fn url_for_object(&self, object: &str) -> Option<String> {
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
}
}
2 changes: 2 additions & 0 deletions src/resources/generated/balance.rs
Expand Up @@ -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 <https://stripe.com/docs/api/balance/balance_object>
#[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).
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/capability.rs
Expand Up @@ -8,6 +8,8 @@ use crate::resources::{Account};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "AccountCapability".
///
/// For more details see <https://stripe.com/docs/api/capabilities/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Capability {
/// The identifier for the capability.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/cash_balance.rs
Expand Up @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
use crate::params::Object;

/// The resource representing a Stripe "cash_balance".
///
/// For more details see <https://stripe.com/docs/api/cash_balance/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CashBalance {
/// A hash of all cash balances available to this customer.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/checkout_session.rs
Expand Up @@ -14,6 +14,8 @@ use crate::resources::{
};

/// The resource representing a Stripe "Session".
///
/// For more details see <https://stripe.com/docs/api/checkout/sessions/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CheckoutSession {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/credit_note_line_item.rs
Expand Up @@ -8,6 +8,8 @@ use crate::resources::{Discount, TaxRate};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "CreditNoteLineItem".
///
/// For more details see <https://stripe.com/docs/api/credit_notes/line_item>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreditNoteLineItem {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/customer_cash_balance_transaction.rs
Expand Up @@ -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 <https://stripe.com/docs/api/cash_balance_transactions/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CustomerCashBalanceTransaction {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/financial_connections_account.rs
Expand Up @@ -8,6 +8,8 @@ use crate::resources::{BankConnectionsResourceAccountholder, FinancialConnection
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "BankConnectionsResourceLinkedAccount".
///
/// For more details see <https://stripe.com/docs/api/financial_connections/accounts/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct FinancialConnectionsAccount {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/financial_connections_session.rs
Expand Up @@ -9,6 +9,8 @@ use crate::resources::{BankConnectionsResourceAccountholder, FinancialConnection
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "BankConnectionsResourceLinkAccountSession".
///
/// For more details see <https://stripe.com/docs/api/financial_connections/sessions/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct FinancialConnectionsSession {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/identity_verification_report.rs
Expand Up @@ -8,6 +8,8 @@ use crate::resources::{Address};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "GelatoVerificationReport".
///
/// For more details see <https://stripe.com/docs/api/identity/verification_reports/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IdentityVerificationReport {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/identity_verification_session.rs
Expand Up @@ -8,6 +8,8 @@ use crate::resources::{Address, IdentityVerificationReport};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "GelatoVerificationSession".
///
/// For more details see <https://stripe.com/docs/api/identity/verification_sessions/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IdentityVerificationSession {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/issuing_authorization.rs
Expand Up @@ -13,6 +13,8 @@ use crate::resources::{
};

/// The resource representing a Stripe "IssuingAuthorization".
///
/// For more details see <https://stripe.com/docs/api/issuing/authorizations/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IssuingAuthorization {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/issuing_card.rs
Expand Up @@ -12,6 +12,8 @@ use crate::resources::{
};

/// The resource representing a Stripe "IssuingCard".
///
/// For more details see <https://stripe.com/docs/api/issuing/cards/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IssuingCard {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/issuing_cardholder.rs
Expand Up @@ -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 <https://stripe.com/docs/api/issuing/cardholders/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IssuingCardholder {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/issuing_dispute.rs
Expand Up @@ -11,6 +11,8 @@ use crate::resources::{
};

/// The resource representing a Stripe "IssuingDispute".
///
/// For more details see <https://stripe.com/docs/api/issuing/disputes/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IssuingDispute {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/issuing_transaction.rs
Expand Up @@ -12,6 +12,8 @@ use crate::resources::{
};

/// The resource representing a Stripe "IssuingTransaction".
///
/// For more details see <https://stripe.com/docs/api/issuing/transactions/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IssuingTransaction {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/login_link.rs
Expand Up @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
use crate::params::{Object, Timestamp};

/// The resource representing a Stripe "LoginLink".
///
/// For more details see <https://stripe.com/docs/api/account/login_link>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct LoginLink {
/// Time at which the object was created.
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/payment_link.rs
Expand Up @@ -11,7 +11,7 @@ use crate::resources::{Account, CheckoutSessionItem, Currency, ShippingRate};

/// The resource representing a Stripe "PaymentLink".
///
/// For more details see <https://stripe.com/docs/api/payment_links/object>
/// For more details see <https://stripe.com/docs/api/payment_links/payment_links/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct PaymentLink {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/radar_value_list.rs
Expand Up @@ -8,6 +8,8 @@ use crate::resources::{RadarValueListItem};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "RadarListList".
///
/// For more details see <https://stripe.com/docs/api/radar/value_lists/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct RadarValueList {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/radar_value_list_item.rs
Expand Up @@ -7,6 +7,8 @@ use crate::params::{Object, Timestamp};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "RadarListListItem".
///
/// For more details see <https://stripe.com/docs/api/radar/value_list_items/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct RadarValueListItem {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/reporting_report_run.rs
Expand Up @@ -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 <https://stripe.com/docs/api/reporting/report_run/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ReportingReportRun {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/reporting_report_type.rs
Expand Up @@ -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 <https://stripe.com/docs/api/reporting/report_type/object>
#[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`.
Expand Down
2 changes: 1 addition & 1 deletion src/resources/generated/review.rs
Expand Up @@ -11,7 +11,7 @@ use crate::resources::{Charge, PaymentIntent, ReviewReason};

/// The resource representing a Stripe "RadarReview".
///
/// For more details see <https://stripe.com/docs/api/reviews/object>
/// For more details see <https://stripe.com/docs/api/radar/reviews/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Review {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/scheduled_query_run.rs
Expand Up @@ -9,6 +9,8 @@ use crate::params::{Object, Timestamp};
use crate::resources::File;

/// The resource representing a Stripe "ScheduledQueryRun".
///
/// For more details see <https://stripe.com/docs/api/sigma/scheduled_queries/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ScheduledQueryRun {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/tax_id.rs
Expand Up @@ -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 <https://stripe.com/docs/api/customer_tax_ids/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxId {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/terminal_configuration.rs
Expand Up @@ -9,6 +9,8 @@ use crate::params::{Expandable, Object};
use crate::resources::File;

/// The resource representing a Stripe "TerminalConfigurationConfiguration".
///
/// For more details see <https://stripe.com/docs/api/terminal/configuration/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalConfiguration {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/terminal_connection_token.rs
Expand Up @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
use crate::params::Object;

/// The resource representing a Stripe "TerminalConnectionToken".
///
/// For more details see <https://stripe.com/docs/api/terminal/connection_tokens/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalConnectionToken {
/// The id of the location that this connection token is scoped to.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/terminal_location.rs
Expand Up @@ -9,6 +9,8 @@ use crate::params::{Metadata, Object};
use crate::resources::Address;

/// The resource representing a Stripe "TerminalLocationLocation".
///
/// For more details see <https://stripe.com/docs/api/terminal/locations/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalLocation {
/// Unique identifier for the object.
Expand Down
2 changes: 2 additions & 0 deletions src/resources/generated/terminal_reader.rs
Expand Up @@ -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 <https://stripe.com/docs/api/terminal/readers/object>
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TerminalReader {
/// Unique identifier for the object.
Expand Down

0 comments on commit fecaa2e

Please sign in to comment.