diff --git a/lib/mix/tasks/generate.ex b/lib/mix/tasks/generate.ex index 0041eafd3..35db6ad0a 100644 --- a/lib/mix/tasks/generate.ex +++ b/lib/mix/tasks/generate.ex @@ -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 diff --git a/lib/openapi/phases/compile.ex b/lib/openapi/phases/compile.ex index 54b19953b..b77975635 100644 --- a/lib/openapi/phases/compile.ex +++ b/lib/openapi/phases/compile.ex @@ -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) @@ -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 diff --git a/test/stripe/util_test.exs b/test/stripe/util_test.exs index 80504f9d9..b2ac3c057 100644 --- a/test/stripe/util_test.exs +++ b/test/stripe/util_test.exs @@ -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