Skip to content

Commit 260d450

Browse files
authored
Merge pull request #332 from arlyon/feat/improve-api-docs
feat: improve api doc code to fix / add more coverage
2 parents 8e7e644 + fecaa2e commit 260d450

29 files changed

+78
-11
lines changed

openapi/src/url_finder.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const APP_USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWeb
77

88
#[derive(Debug)]
99
pub struct UrlFinder {
10-
html: String,
10+
flattened_api_sections: serde_json::Map<String, serde_json::Value>,
1111
}
1212

1313
impl UrlFinder {
@@ -17,8 +17,16 @@ impl UrlFinder {
1717

1818
if resp.status().is_success() {
1919
let text = resp.text()?;
20-
if text.contains("title: 'Stripe API Reference'") {
21-
Ok(Self { html: text })
20+
if let Some(line) = text.lines().find(|l| l.contains("flattenedAPISections: {")) {
21+
println!("{}", line);
22+
Ok(Self {
23+
flattened_api_sections: serde_json::from_str(
24+
line.trim()
25+
.trim_start_matches("flattenedAPISections: ")
26+
.trim_end_matches(","),
27+
)
28+
.expect("should be valid json"),
29+
})
2230
} else {
2331
Err(anyhow!("stripe api returned unexpected document"))
2432
}
@@ -30,12 +38,19 @@ impl UrlFinder {
3038

3139
pub fn url_for_object(&self, object: &str) -> Option<String> {
3240
let object_name = object.replace('.', "_").to_snake_case();
33-
let doc_url = format!("/{}s/object", object_name);
34-
if self.html.contains(&doc_url) {
35-
Some(format!("https://stripe.com/docs/api{}", doc_url))
36-
} else {
37-
log::warn!("{} not in html", doc_url);
38-
None
41+
let object_names = [format!("{}_object", object_name), object_name];
42+
for name in object_names {
43+
if let Some(path) = self
44+
.flattened_api_sections
45+
.get(&name)
46+
.and_then(|o| o.as_object().expect("this should be an object").get("path"))
47+
.and_then(|s| s.as_str())
48+
{
49+
return Some(format!("https://stripe.com/docs/api{}", path));
50+
}
3951
}
52+
53+
log::warn!("{} not in html", object);
54+
None
4055
}
4156
}

src/resources/generated/balance.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::params::Object;
88
use crate::resources::Currency;
99

1010
/// The resource representing a Stripe "Balance".
11+
///
12+
/// For more details see <https://stripe.com/docs/api/balance/balance_object>
1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub struct Balance {
1315
/// 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).

src/resources/generated/capability.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::resources::{Account};
88
use serde::{Deserialize, Serialize};
99

1010
/// The resource representing a Stripe "AccountCapability".
11+
///
12+
/// For more details see <https://stripe.com/docs/api/capabilities/object>
1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub struct Capability {
1315
/// The identifier for the capability.

src/resources/generated/cash_balance.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize};
77
use crate::params::Object;
88

99
/// The resource representing a Stripe "cash_balance".
10+
///
11+
/// For more details see <https://stripe.com/docs/api/cash_balance/object>
1012
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1113
pub struct CashBalance {
1214
/// A hash of all cash balances available to this customer.

src/resources/generated/checkout_session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use crate::resources::{
1515
};
1616

1717
/// The resource representing a Stripe "Session".
18+
///
19+
/// For more details see <https://stripe.com/docs/api/checkout/sessions/object>
1820
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1921
pub struct CheckoutSession {
2022
/// Unique identifier for the object.

src/resources/generated/credit_note_line_item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::resources::{Discount, TaxRate};
88
use serde::{Deserialize, Serialize};
99

1010
/// The resource representing a Stripe "CreditNoteLineItem".
11+
///
12+
/// For more details see <https://stripe.com/docs/api/credit_notes/line_item>
1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub struct CreditNoteLineItem {
1315
/// Unique identifier for the object.

src/resources/generated/customer_cash_balance_transaction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::resources::{Currency, Customer, PaymentIntent, Refund};
88
use serde::{Deserialize, Serialize};
99

1010
/// The resource representing a Stripe "CustomerCashBalanceTransaction".
11+
///
12+
/// For more details see <https://stripe.com/docs/api/cash_balance_transactions/object>
1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub struct CustomerCashBalanceTransaction {
1315
/// Unique identifier for the object.

src/resources/generated/financial_connections_account.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::resources::{BankConnectionsResourceAccountholder, FinancialConnection
88
use serde::{Deserialize, Serialize};
99

1010
/// The resource representing a Stripe "BankConnectionsResourceLinkedAccount".
11+
///
12+
/// For more details see <https://stripe.com/docs/api/financial_connections/accounts/object>
1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub struct FinancialConnectionsAccount {
1315
/// Unique identifier for the object.

src/resources/generated/financial_connections_session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::resources::{BankConnectionsResourceAccountholder, FinancialConnection
99
use serde::{Deserialize, Serialize};
1010

1111
/// The resource representing a Stripe "BankConnectionsResourceLinkAccountSession".
12+
///
13+
/// For more details see <https://stripe.com/docs/api/financial_connections/sessions/object>
1214
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1315
pub struct FinancialConnectionsSession {
1416
/// Unique identifier for the object.

src/resources/generated/identity_verification_report.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::resources::{Address};
88
use serde::{Deserialize, Serialize};
99

1010
/// The resource representing a Stripe "GelatoVerificationReport".
11+
///
12+
/// For more details see <https://stripe.com/docs/api/identity/verification_reports/object>
1113
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1214
pub struct IdentityVerificationReport {
1315
/// Unique identifier for the object.

0 commit comments

Comments
 (0)