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 6ac61c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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
18 changes: 17 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.id
|> to_func_name()
|> Macro.underscore()
|> String.to_atom()

success_response_spec = return_spec(operation_definition.success_response)

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

# 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_id) do
case Map.get(@operation_identity_mapping, operation_id) do
nil -> raise "Unknown operation id: #{inspect(operation_id)}"
name -> name
end
end
end
9 changes: 7 additions & 2 deletions test/stripe/util_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ defmodule Stripe.UtilTest do

assert object_name_to_module("billing_portal.session") == Stripe.BillingPortal.Session
assert object_name_to_module("checkout.session") == Stripe.Checkout.Session
assert object_name_to_module("identity.verification_report") == Stripe.Identity.VerificationReport
assert object_name_to_module("identity.verification_session") == Stripe.Identity.VerificationSession

assert object_name_to_module("identity.verification_report") ==
Stripe.Identity.VerificationReport

assert object_name_to_module("identity.verification_session") ==
Stripe.Identity.VerificationSession

assert object_name_to_module("issuing.authorization") == Stripe.Issuing.Authorization
assert object_name_to_module("issuing.card") == Stripe.Issuing.Card
assert object_name_to_module("issuing.cardholder") == Stripe.Issuing.Cardholder
Expand Down

0 comments on commit 6ac61c8

Please sign in to comment.