Skip to content

Commit

Permalink
Adds support for custom metadata for aws-elixir.
Browse files Browse the repository at this point in the history
This adds support for custom metadata for elixir (see #92). It also
adds code that was removed in #103 which appears to have inadvertently
removed erlang support, as well as functions necessary for elixir
support (e.g., `collect_request_headers_parameters`).
  • Loading branch information
jhosteny committed Nov 19, 2024
1 parent 9c2005f commit 6b50f2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/aws_codegen/rest_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ defmodule AWS.CodeGen.RestService do
function_name = AWS.CodeGen.Name.to_snake_case(operation)
request_header_parameters = collect_request_header_parameters(language, api_spec, operation)

request_headers_parameters =
collect_request_headers_parameters(language, api_spec, operation)

is_required = fn param -> param.required end
required_query_parameters = Enum.filter(query_parameters, is_required)
required_request_header_parameters = Enum.filter(request_header_parameters, is_required)
Expand All @@ -266,7 +269,8 @@ defmodule AWS.CodeGen.RestService do
"GET" ->
case language do
:elixir ->
2 + length(request_header_parameters) + length(query_parameters)
2 + length(request_header_parameters) + length(request_headers_parameters) +
length(query_parameters)

:erlang ->
4 + length(required_request_header_parameters) + length(required_query_parameters)
Expand Down Expand Up @@ -295,6 +299,7 @@ defmodule AWS.CodeGen.RestService do
query_parameters: query_parameters,
required_query_parameters: required_query_parameters,
request_header_parameters: request_header_parameters,
request_headers_parameters: request_headers_parameters,
required_request_header_parameters: required_request_header_parameters,
response_header_parameters:
collect_response_header_parameters(language, api_spec, operation),
Expand Down Expand Up @@ -338,6 +343,10 @@ defmodule AWS.CodeGen.RestService do
collect_parameters(language, api_spec, operation, "input", "smithy.api#httpHeader")
end

defp collect_request_headers_parameters(language, api_spec, operation) do
collect_parameters(language, api_spec, operation, "input", "smithy.api#httpPrefixHeaders")
end

defp collect_response_header_parameters(language, api_spec, operation) do
collect_parameters(language, api_spec, operation, "output", "smithy.api#httpHeader")
end
Expand Down
10 changes: 8 additions & 2 deletions priv/rest.ex.eex
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.fu
{"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %>
]
|> Request.build_params(input)<% else %>
headers = []<% end %><%= if length(action.query_parameters) > 0 do %>
headers = []<% end %><%= if length(action.request_headers_parameters) > 0 do %>
{custom_headers, input} =
[<%= for parameter <- action.request_headers_parameters do %>
{"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %>
]
|> Request.build_params(input)<% else %>
custom_headers = []<% end %><%= if length(action.query_parameters) > 0 do %>
{query_params, input} =
[<%= for parameter <- action.query_parameters do %>
{"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %>
Expand Down Expand Up @@ -168,6 +174,6 @@ def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.fu
metadata()
<% end %>

Request.request_rest(client, meta, <%= AWS.CodeGen.RestService.Action.method(action) %>, url_path, query_params, headers, input, options, <%= inspect(action.success_status_code) %>)<% end %>
Request.request_rest(client, meta, <%= AWS.CodeGen.RestService.Action.method(action) %>, url_path, query_params, custom_headers ++ headers, input, options, <%= inspect(action.success_status_code) %>)<% end %>
end<% end %>
end

0 comments on commit 6b50f2a

Please sign in to comment.