Skip to content

Commit

Permalink
Simplify rest_service:function_parameter_types
Browse files Browse the repository at this point in the history
  • Loading branch information
onno-vos-dev committed Mar 14, 2024
1 parent 44a1cc4 commit 167bbb4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
47 changes: 21 additions & 26 deletions lib/aws_codegen/rest_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,38 +162,33 @@ defmodule AWS.CodeGen.RestService do
end

def required_function_parameter_types(action) do
function_parameter_types(action, true)
function_parameter_types(action.method, action, true)
end

def required_query_map_types(action) do
function_parameter_types(action, true)
function_parameter_types(action.method, action, true)
end

def function_parameter_types(action, required_only \\ false) do
def function_parameter_types("GET", action, false = _required_only) do
language = action.language
Enum.join([
join_parameter_types(action.url_parameters, language)
| case action.method do
"GET" ->
case required_only do
false ->
[
join_parameter_types(action.query_parameters, language),
join_parameter_types(action.request_header_parameters, language),
join_parameter_types(action.request_headers_parameters, language)
]

true ->
[
join_parameter_types(action.required_query_parameters, language),
join_parameter_types(action.required_request_header_parameters, language)
]
end

_ ->
[]
end
])
Enum.join(
[join_parameter_types(action.url_parameters, language),
join_parameter_types(action.query_parameters, language),
join_parameter_types(action.request_header_parameters, language),
join_parameter_types(action.request_headers_parameters, language)
])
end
def function_parameter_types("GET", action, true = _required_only) do
language = action.language
Enum.join(
[join_parameter_types(action.url_parameters, language),
join_parameter_types(action.required_query_parameters, language),
join_parameter_types(action.required_request_header_parameters, language)
])
end
def function_parameter_types(_method, action, _required_only) do
language = action.language
join_parameter_types(action.url_parameters, language)
end

defp join_parameter_types(parameters, language) do
Expand Down
4 changes: 2 additions & 2 deletions priv/rest.ex.eex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule <%= context.module_name %> do
@doc """
<%= action.docstring %>
"""<% end %><%= if action.method == "GET" do %>
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.RestService.function_parameter_types(action)%>, list()) :: <%= AWS.CodeGen.Util.return_type(context.language, action)%>
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.RestService.function_parameter_types(action.method, action, false)%>, list()) :: <%= AWS.CodeGen.Util.return_type(context.language, action)%>
def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.function_parameters(action) %>, options \\ []) do
url_path = "<%= AWS.CodeGen.RestService.Action.url_path(action) %>"
headers = []<%= for parameter <- action.request_header_parameters do %>
Expand Down Expand Up @@ -115,7 +115,7 @@ defmodule <%= context.module_name %> do
<% end %>

Request.request_rest(client, meta, :get, url_path, query_params, headers, nil, options, <%= inspect(action.success_status_code) %>)<% else %>
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.RestService.function_parameter_types(action)%>, <%= AWS.CodeGen.Util.function_argument_type(context.language, action)%>, list()) :: <%= AWS.CodeGen.Util.return_type(context.language, action)%>
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.RestService.function_parameter_types(action.method, action, false)%>, <%= AWS.CodeGen.Util.function_argument_type(context.language, action)%>, list()) :: <%= AWS.CodeGen.Util.return_type(context.language, action)%>
def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.function_parameters(action) %>, input, options \\ []) do
url_path = "<%= AWS.CodeGen.RestService.Action.url_path(action) %>"<%= if length(action.request_header_parameters) > 0 do %>
{headers, input} =
Expand Down

0 comments on commit 167bbb4

Please sign in to comment.