-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Copy from striped * another * replace with Stripe.Request * delete files * updates with base url * Fix more core_resources * Passing payment_methods tests * Passing subscription tests * Passing issuing tests * Passing fraud tests * most of connect tests passing * fix * fix after rebase * add file upload * passing tests * more cleanup * fix dupe module * cleanup deps * add assertion for Stripe-Account param in opts * add test for put Stripe-Version header * add test for exported functions * update maintainers
- Loading branch information
Showing
146 changed files
with
128,005 additions
and
12,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule Stripe.OpenApi do | ||
@moduledoc false | ||
|
||
alias Stripe.OpenApi | ||
|
||
defmacro __using__(opts) do | ||
quote do | ||
@pipeline Stripe.OpenApi.pipeline(unquote(opts)) | ||
|
||
{:ok, blueprint} = Stripe.OpenApi.run(@pipeline) | ||
|
||
@version blueprint.api_version | ||
end | ||
end | ||
|
||
def pipeline(options \\ []) do | ||
[ | ||
{OpenApi.Phases.Parse, options}, | ||
{OpenApi.Phases.BuildModules, options}, | ||
{OpenApi.Phases.BuildOperations, options}, | ||
{OpenApi.Phases.BuildDocumentation, options}, | ||
{OpenApi.Phases.Compile, options}, | ||
{OpenApi.Phases.Version, options} | ||
] | ||
end | ||
|
||
def run(pipeline) do | ||
{:ok, _} = | ||
pipeline | ||
|> List.flatten() | ||
|> run_phase(%OpenApiGen.Blueprint{}) | ||
end | ||
|
||
defp run_phase(pipeline, input) | ||
|
||
defp run_phase([], input) do | ||
{:ok, input} | ||
end | ||
|
||
defp run_phase([phase_config | todo], input) do | ||
{phase, options} = phase_invocation(phase_config) | ||
|
||
case phase.run(input, options) do | ||
{:ok, result} -> | ||
run_phase(todo, result) | ||
|
||
{:error, message} -> | ||
{:error, message} | ||
|
||
_ -> | ||
{:error, "Last phase did not return a valid result tuple."} | ||
end | ||
end | ||
|
||
defp phase_invocation({phase, options}) when is_list(options) do | ||
{phase, options} | ||
end | ||
|
||
defp phase_invocation(phase) do | ||
{phase, []} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule OpenApiGen.Blueprint do | ||
@moduledoc false | ||
defstruct [:components, :source, :operations, :modules, :api_version] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule OpenApiGen.Blueprint.AnyOf do | ||
@moduledoc false | ||
defstruct any_of: [] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule OpenApiGen.Blueprint.ListOf do | ||
@moduledoc false | ||
defstruct [ | ||
:type_of | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule OpenApiGen.Blueprint.Module do | ||
@moduledoc false | ||
defstruct [:name, :prefix, :description] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule OpenApiGen.Blueprint.Operation do | ||
@moduledoc false | ||
defstruct [ | ||
:id, | ||
:method, | ||
:path, | ||
:name, | ||
:description, | ||
:parameters, | ||
:path_parameters, | ||
:query_parameters, | ||
:deprecated, | ||
:operation, | ||
:body_parameters, | ||
:success_response | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule OpenApiGen.Blueprint.Parameter do | ||
@moduledoc false | ||
defstruct [:in, :name, :required, :schema] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule OpenApiGen.Blueprint.Parameter.Schema do | ||
@moduledoc false | ||
defstruct [:name, :title, :type, items: [], properties: [], any_of: []] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule OpenApiGen.Blueprint.Reference do | ||
@moduledoc false | ||
defstruct [ | ||
:name | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule OpenApiGen.Blueprint.Schema do | ||
@moduledoc false | ||
defstruct [:name, :description, :module, operations: [], properties: [], expandable_fields: []] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule OpenApiGen.Blueprint.SearchResult do | ||
@moduledoc false | ||
defstruct [ | ||
:type_of | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Stripe.OpenApi.Path do | ||
@moduledoc false | ||
def replace_path_params(path, path_param_defs, path_params_values) do | ||
{path, []} = | ||
path_param_defs | ||
|> Enum.reduce({path, path_params_values}, fn path_param_def, | ||
{path, [path_param_value | values]} -> | ||
path_param_name = path_param_def.name | ||
|
||
path = String.replace(path, "{#{path_param_name}}", path_param_value) | ||
{path, values} | ||
end) | ||
|
||
path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Stripe.OpenApi.Phases.BuildDocumentation do | ||
@moduledoc false | ||
def run(blueprint, _options \\ []) do | ||
operations = | ||
Enum.map(blueprint.operations, fn {key, operation} -> | ||
{key, build_description(operation)} | ||
end) | ||
|> Map.new() | ||
|
||
{:ok, %{blueprint | operations: operations}} | ||
end | ||
|
||
defp build_description(operation) do | ||
%{operation | description: do_build_description(operation)} | ||
end | ||
|
||
defp do_build_description(operation) do | ||
description = operation.description | ||
|
||
""" | ||
#{description} | ||
#### Details | ||
* Method: `#{operation.method}` | ||
* Path: `#{operation.path}` | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Stripe.OpenApi.Phases.BuildModules do | ||
@moduledoc false | ||
def run(blueprint, _options \\ []) do | ||
components = | ||
for {name, map} <- blueprint.source["components"]["schemas"], | ||
# map["x-stripeOperations"] != nil, | ||
map["x-resourceId"] != nil || name == "api_errors", | ||
into: %{} do | ||
resource = | ||
(map["x-resourceId"] || name) |> String.split(".") |> Enum.map(&Macro.camelize/1) | ||
|
||
{name, | ||
%OpenApiGen.Blueprint.Schema{ | ||
name: name, | ||
description: map["description"], | ||
operations: | ||
(map["x-stripeOperations"] || []) | ||
|> Enum.uniq_by(& &1["method_name"]) # see connect/account_test.exs | ||
|> Enum.map(&%{&1 | "method_name" => Macro.underscore(&1["method_name"])}), | ||
module: Module.concat(["Stripe" | resource]), | ||
properties: map["properties"] || %{}, | ||
expandable_fields: | ||
Map.get(map, "x-expandableFields", []) |> Enum.map(&String.to_atom/1) | ||
}} | ||
end | ||
|
||
{:ok, %{blueprint | components: components}} | ||
end | ||
end |
Oops, something went wrong.