Skip to content

Commit

Permalink
fix: operation name
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed Aug 22, 2024
1 parent 44cf0e4 commit f436cb6
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .latest-tag-stripe-openapi-sdk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v755
v753
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
CURRENT_VERSION := $(shell cat .latest-tag-stripe-openapi-sdk)

download-openapi-current:
@echo "Tag: $(CURRENT_VERSION)"
@echo "Downloading https://raw.githubusercontent.com/stripe/openapi/$(CURRENT_VERSION)/openapi/spec3.sdk.json to ./priv/openapi/spec3.sdk.json"
@curl -o ./priv/openapi/spec3.sdk.json https://raw.githubusercontent.com/stripe/openapi/$(CURRENT_VERSION)/openapi/spec3.sdk.json

generate:
mix stripe.generate
mix format

gen-changelog:
npx auto-changelog --unreleased

Expand Down
15 changes: 8 additions & 7 deletions lib/generated/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Stripe.Account do
)

(
@typedoc "The company's primary address."
@typedoc "The individual's primary address."
@type address :: %{
optional(:city) => binary,
optional(:country) => binary,
Expand Down Expand Up @@ -119,8 +119,8 @@ defmodule Stripe.Account do
)

(
@typedoc "Settings specific to Bacs Direct Debit payments."
@type bacs_debit_payments :: %{optional(:display_name) => binary}
@typedoc "The bacs_debit_payments capability."
@type bacs_debit_payments :: %{optional(:requested) => boolean}
)

(
Expand Down Expand Up @@ -217,8 +217,8 @@ defmodule Stripe.Account do
)

(
@typedoc "Settings specific to the account's use of the Card Issuing product."
@type card_issuing :: %{optional(:tos_acceptance) => tos_acceptance}
@typedoc "The card_issuing capability."
@type card_issuing :: %{optional(:requested) => boolean}
)

(
Expand Down Expand Up @@ -583,11 +583,12 @@ defmodule Stripe.Account do
)

(
@typedoc "Details on the account's acceptance of the Stripe Treasury Services Agreement."
@typedoc "Details on the account's acceptance of the [Stripe Services Agreement](https://stripe.com/docs/connect/updating-accounts#tos-acceptance)."
@type tos_acceptance :: %{
optional(:date) => integer,
optional(:ip) => binary,
optional(:user_agent) => binary | binary
optional(:service_agreement) => binary,
optional(:user_agent) => binary
}
)

Expand Down
7 changes: 5 additions & 2 deletions lib/generated/checkout__session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,11 @@ defmodule Stripe.Checkout.Session do
)

(
@typedoc "The parameters used to automatically create a Transfer when the payment succeeds.\nFor more information, see the PaymentIntents [use case for connected accounts](https://stripe.com/docs/payments/connected-accounts)."
@type transfer_data :: %{optional(:amount) => integer, optional(:destination) => binary}
@typedoc "If specified, the funds from the subscription's invoices will be transferred to the destination and the ID of the resulting transfers will be found on the resulting charges."
@type transfer_data :: %{
optional(:amount_percent) => number,
optional(:destination) => binary
}
)

(
Expand Down
111 changes: 67 additions & 44 deletions lib/generated/payment_intent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc "Shipping address."
@typedoc nil
@type address :: %{
optional(:city) => binary,
optional(:country) => binary,
Expand Down Expand Up @@ -315,8 +315,33 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc nil
@type fpx :: %{optional(:setup_future_usage) => :none}
@typedoc "If this is an `fpx` PaymentMethod, this hash contains details about the FPX payment method."
@type fpx :: %{
optional(:account_holder_type) => :company | :individual,
optional(:bank) =>
:affin_bank
| :agrobank
| :alliance_bank
| :ambank
| :bank_islam
| :bank_muamalat
| :bank_of_china
| :bank_rakyat
| :bsn
| :cimb
| :deutsche_bank
| :hong_leong_bank
| :hsbc
| :kfh
| :maybank2e
| :maybank2u
| :ocbc
| :pb_enterprise
| :public_bank
| :rhb
| :standard_chartered
| :uob
}
)

(
Expand All @@ -330,25 +355,8 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc "If this is an `ideal` PaymentMethod, this hash contains details about the iDEAL payment method."
@type ideal :: %{
optional(:bank) =>
:abn_amro
| :asn_bank
| :bunq
| :handelsbanken
| :ing
| :knab
| :moneyou
| :n26
| :rabobank
| :regiobank
| :revolut
| :sns_bank
| :triodos_bank
| :van_lanschot
| :yoursafe
}
@typedoc nil
@type ideal :: %{optional(:setup_future_usage) => :none | :off_session}
)

(
Expand Down Expand Up @@ -435,18 +443,8 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc "Configuration options for setting up an eMandate for cards issued in India."
@type mandate_options :: %{
optional(:amount) => integer,
optional(:amount_type) => :fixed | :maximum,
optional(:description) => binary,
optional(:end_date) => integer,
optional(:interval) => :day | :month | :sporadic | :week | :year,
optional(:interval_count) => integer,
optional(:reference) => binary,
optional(:start_date) => integer,
optional(:supported_types) => list(:india)
}
@typedoc "Additional fields for Mandate creation"
@type mandate_options :: %{optional(:collection_method) => :paper}
)

(
Expand All @@ -473,10 +471,34 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc nil
@typedoc "If this is a `p24` PaymentMethod, this hash contains details about the P24 payment method."
@type p24 :: %{
optional(:setup_future_usage) => :none,
optional(:tos_shown_and_accepted) => boolean
optional(:bank) =>
:alior_bank
| :bank_millennium
| :bank_nowy_bfg_sa
| :bank_pekao_sa
| :banki_spbdzielcze
| :blik
| :bnp_paribas
| :boz
| :citi_handlowy
| :credit_agricole
| :envelobank
| :etransfer_pocztowy24
| :getin_bank
| :ideabank
| :ing
| :inteligo
| :mbank_mtransfer
| :nest_przelew
| :noble_pay
| :pbac_z_ipko
| :plus_bank
| :santander_przelew24
| :tmobile_usbugi_bankowe
| :toyota_bank
| :volkswagen_bank
}
)

Expand Down Expand Up @@ -654,7 +676,7 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc "Options to configure Radar. See [Radar Session](https://stripe.com/docs/radar/radar-session) for more information."
@typedoc "Options to configure Radar. Learn more about [Radar Sessions](https://stripe.com/docs/radar/radar-session)."
@type radar_options :: %{optional(:session) => binary}
)

Expand Down Expand Up @@ -710,13 +732,14 @@ defmodule Stripe.PaymentIntent do
)

(
@typedoc "If this is an `us_bank_account` PaymentMethod, this hash contains details about the US bank account payment method."
@typedoc nil
@type us_bank_account :: %{
optional(:account_holder_type) => :company | :individual,
optional(:account_number) => binary,
optional(:account_type) => :checking | :savings,
optional(:financial_connections_account) => binary,
optional(:routing_number) => binary
optional(:financial_connections) => financial_connections,
optional(:mandate_options) => mandate_options,
optional(:networks) => networks,
optional(:preferred_settlement_speed) => :fastest | :standard,
optional(:setup_future_usage) => :none | :off_session | :on_session,
optional(:verification_method) => :automatic | :instant | :microdeposits
}
)

Expand Down
15 changes: 7 additions & 8 deletions lib/generated/setup_intent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ defmodule Stripe.SetupIntent do
)

(
@typedoc "If this is a `sepa_debit` SetupIntent, this sub-hash contains details about the SEPA Debit payment method options."
@type sepa_debit :: %{optional(:mandate_options) => map()}
@typedoc "If this is a `sepa_debit` PaymentMethod, this hash contains details about the SEPA debit bank account."
@type sepa_debit :: %{optional(:iban) => binary}
)

(
Expand All @@ -469,13 +469,12 @@ defmodule Stripe.SetupIntent do
)

(
@typedoc "If this is an `us_bank_account` PaymentMethod, this hash contains details about the US bank account payment method."
@typedoc "If this is a `us_bank_account` SetupIntent, this sub-hash contains details about the US bank account payment method options."
@type us_bank_account :: %{
optional(:account_holder_type) => :company | :individual,
optional(:account_number) => binary,
optional(:account_type) => :checking | :savings,
optional(:financial_connections_account) => binary,
optional(:routing_number) => binary
optional(:financial_connections) => financial_connections,
optional(:mandate_options) => mandate_options,
optional(:networks) => networks,
optional(:verification_method) => :automatic | :instant | :microdeposits
}
)

Expand Down
4 changes: 2 additions & 2 deletions lib/generated/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Stripe.Token do
)

(
@typedoc "The company's primary address."
@typedoc "The person's address."
@type address :: %{
optional(:city) => binary,
optional(:country) => binary,
Expand All @@ -64,7 +64,7 @@ defmodule Stripe.Token do
)

(
@typedoc "The Kanji variation of the company's primary address (Japan only)."
@typedoc "The Kanji variation of the person's address (Japan only)."
@type address_kanji :: %{
optional(:city) => binary,
optional(:country) => binary,
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/generate.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Mix.Tasks.Stripe.Generate do
@moduledoc "The hello mix task: `mix help hello`"
@moduledoc "The hello mix task: `mix stripe.generate`"
use Mix.Task

def run(_) do
Expand Down
40 changes: 39 additions & 1 deletion lib/openapi/phases/compile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ defmodule Stripe.OpenApi.Phases.Compile do
end
end)

function_name = String.to_atom(operation["method_name"])
function_name =
operation_definition
|> to_func_name(operation)
|> Macro.underscore()
|> String.to_atom()

success_response_spec = return_spec(operation_definition.success_response)

Expand Down Expand Up @@ -509,4 +513,38 @@ defmodule Stripe.OpenApi.Phases.Compile do
defp lookup_operation(path, operations) do
Map.get(operations, path)
end

require Logger

# NOTE: This is a mapping of operation ids to function names. This is necessary
# to avoid breaking changes. In the future, we should remove this mapping and
# use the operation id directly as the function name.
@operation_identity_mapping %{}

defp to_func_name(operation_definition, operation) do
case Map.get(@operation_identity_mapping, operation_definition.id) do
nil ->
# Logger.error("""
# Unregistered Operation
#
# - Stripe Extension: #{inspect(operation)}
#
#
# - Operation: #{inspect(operation_definition)}
#
# - Suggested Mapping: "#{operation_definition.id}" => "#{operation["method_name"]}",
# """)

content = ~s("#{operation_definition.id}" => "#{operation["method_name"]}",\n)

File.rm("./mapping")
File.touch("./mapping")
File.write!("./mapping", content, [:append])

operation["method_name"]

name ->
name
end
end
end
Loading

0 comments on commit f436cb6

Please sign in to comment.