Skip to content

Commit

Permalink
Fix API Gateway Management API to include Stage on all endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
onno-vos-dev committed Mar 17, 2024
1 parent a3eb9c6 commit b66f8eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
36 changes: 19 additions & 17 deletions priv/rest.erl.eex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

<%= if context.docstring != "%% @doc" do %><%= context.docstring %><% end %>
-module(<%= context.module_name %>).

<%= if context.module_name == "aws_apigatewaymanagementapi" do %>
-export([<%= Enum.map(context.actions, fn(action) -> if action.method == "GET" do ["#{action.function_name}/#{action.arity - 2}"] else [] end ++ ["#{action.function_name}/#{action.arity}", "#{action.function_name}/#{action.arity + 1}"] end) |> List.flatten |> Enum.join(",\n ") %>]).
<% else %>
-export([<%= Enum.map(context.actions, fn(action) -> if action.method == "GET" do ["#{action.function_name}/#{action.arity - 3}"] else [] end ++ ["#{action.function_name}/#{action.arity - 1}", "#{action.function_name}/#{action.arity}"] end) |> List.flatten |> Enum.join(",\n ") %>]).

<% end %>
-include_lib("hackney/include/hackney_lib.hrl").

<%= for {type_name, type_fields} <- AWS.CodeGen.Types.types(context) do %>
Expand Down Expand Up @@ -48,23 +50,23 @@ end) %>
%%====================================================================
<%= for action <- context.actions do %>
<%= action.docstring %><%= if action.method == "GET" do %>
-spec <%= action.function_name %>(aws_client:aws_client()<%= AWS.CodeGen.Types.required_function_parameter_types(action) %>) ->
-spec <%= action.function_name %>(aws_client:aws_client()<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, list() | binary()<% end %><%= AWS.CodeGen.Types.required_function_parameter_types(action) %>) ->
<%= AWS.CodeGen.Types.return_type(context.language, action)%>.
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.required_function_parameters(action) %>)
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.required_function_parameters(action) %>)
when is_map(Client) ->
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.required_function_parameters(action) %>, #{}, #{}).
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.required_function_parameters(action) %>, #{}, #{}).

-spec <%= action.function_name %>(aws_client:aws_client()<%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, map(), map()) ->
-spec <%= action.function_name %>(aws_client:aws_client()<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, list() | binary()<% end %><%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, map(), map()) ->
<%= AWS.CodeGen.Types.return_type(context.language, action)%>.
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.required_function_parameters(action) %>, QueryMap, HeadersMap)
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.required_function_parameters(action) %>, QueryMap, HeadersMap)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap) ->
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.required_function_parameters(action) %>, QueryMap, HeadersMap, []).
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.required_function_parameters(action) %>, QueryMap, HeadersMap, []).

-spec <%= action.function_name %>(aws_client:aws_client()<%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, map(), map(), proplists:proplist()) ->
-spec <%= action.function_name %>(aws_client:aws_client()<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, list() | binary()<% end %><%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, map(), map(), proplists:proplist()) ->
<%= AWS.CodeGen.Types.return_type(context.language, action)%>.
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.required_function_parameters(action) %>, QueryMap, HeadersMap, Options0)
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.required_function_parameters(action) %>, QueryMap, HeadersMap, Options0)
when is_map(Client), is_map(QueryMap), is_map(HeadersMap), is_list(Options0) ->
Path = ["<%= AWS.CodeGen.RestService.Action.url_path(action) %>"],<%= if AWS.CodeGen.RestService.Context.s3_context?(context) do %>
Path = ["<%= if context.module_name == "aws_apigatewaymanagementapi" do %>/", Stage, "<% end %><%= AWS.CodeGen.RestService.Action.url_path(action) %>"],<%= if AWS.CodeGen.RestService.Context.s3_context?(context) do %>
<%= if !String.contains?("Bucket", AWS.CodeGen.RestService.required_function_parameters(action)) do %><% else %> Bucket = undefined,<% end %><% end %>
SuccessStatusCode = <%= inspect(action.success_status_code) %>,
{SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, <%= action.send_body_as_binary? %>),
Expand Down Expand Up @@ -111,16 +113,16 @@ end) %>
end.<% else %>
request(Client, get, Path, Query_, Headers, undefined, Options, SuccessStatusCode<%= if AWS.CodeGen.RestService.Context.s3_context?(context) do %>, Bucket<% end %>).<% end %>
<% else %>
-spec <%= action.function_name %>(aws_client:aws_client()<%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, <%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>) ->
-spec <%= action.function_name %>(aws_client:aws_client()<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, list() | binary()<% end %><%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, <%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>) ->
<%= AWS.CodeGen.Types.return_type(context.language, action)%>.
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.function_parameters(action) %>, Input) ->
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.function_parameters(action) %>, Input, []).
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.function_parameters(action) %>, Input) ->
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.function_parameters(action) %>, Input, []).

-spec <%= action.function_name %>(aws_client:aws_client()<%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, <%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>, proplists:proplist()) ->
-spec <%= action.function_name %>(aws_client:aws_client()<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, list() | binary()<% end %><%= AWS.CodeGen.Types.required_function_parameter_types(action) %>, <%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>, proplists:proplist()) ->
<%= AWS.CodeGen.Types.return_type(context.language, action)%>.
<%= action.function_name %>(Client<%= AWS.CodeGen.RestService.function_parameters(action) %>, Input0, Options0) ->
<%= action.function_name %>(Client<%= if context.module_name == "aws_apigatewaymanagementapi" do %>, Stage<% end %><%= AWS.CodeGen.RestService.function_parameters(action) %>, Input0, Options0) ->
Method = <%= AWS.CodeGen.RestService.Action.method(action) %>,
Path = ["<%= AWS.CodeGen.RestService.Action.url_path(action) %>"],<%= if AWS.CodeGen.RestService.Context.s3_context?(context) do %>
Path = ["<%= if context.module_name == "aws_apigatewaymanagementapi" do %>/", Stage, "<% end %><%= AWS.CodeGen.RestService.Action.url_path(action) %>"],<%= if AWS.CodeGen.RestService.Context.s3_context?(context) do %>
<%= if !String.contains?("Bucket", AWS.CodeGen.RestService.required_function_parameters(action)) do %><% else %> Bucket = undefined,<% end %><% end %>
SuccessStatusCode = <%= inspect(action.success_status_code) %>,
{SendBodyAsBinary, Options1} = proplists_take(send_body_as_binary, Options0, <%= action.send_body_as_binary? %>),
Expand Down
12 changes: 6 additions & 6 deletions priv/rest.ex.eex
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ defmodule <%= context.module_name %> do
@doc """
<%= action.docstring %>
"""<% end %><%= if action.method == "GET" do %>
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.Types.function_parameter_types(action.method, action, false)%>, list()) :: <%= AWS.CodeGen.Types.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) %>"
@spec <%= action.function_name %>(map()<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>, String.t()<% end %><%= AWS.CodeGen.Types.function_parameter_types(action.method, action, false)%>, list()) :: <%= AWS.CodeGen.Types.return_type(context.language, action)%>
def <%= action.function_name %>(%Client{} = client<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>, stage<% end %><%= AWS.CodeGen.RestService.function_parameters(action) %>, options \\ []) do
url_path = "<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>/#{stage}<% end %><%= AWS.CodeGen.RestService.Action.url_path(action) %>"
headers = []<%= for parameter <- action.request_header_parameters do %>
headers = if !is_nil(<%= parameter.code_name %>) do
[{"<%= parameter.location_name %>", <%= parameter.code_name %>} | headers]
Expand Down Expand Up @@ -115,9 +115,9 @@ 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.Types.function_parameter_types(action.method, action, false)%>, <%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>, list()) :: <%= AWS.CodeGen.Types.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 %>
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.Types.function_parameter_types(action.method, action, false)%>, <%= if context.module_name == "AWS.ApiGatewayManagementApi" do %> String.t(), <% end %><%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>, list()) :: <%= AWS.CodeGen.Types.return_type(context.language, action)%>
def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.function_parameters(action) %>, <%= if context.module_name == "AWS.ApiGatewayManagementApi" do %> stage, <% end %>input, options \\ []) do
url_path = "<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>/#{stage}<% end %><%= AWS.CodeGen.RestService.Action.url_path(action) %>"<%= if length(action.request_header_parameters) > 0 do %>
{headers, input} =
[<%= for parameter <- action.request_header_parameters do %>
{"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %>
Expand Down

0 comments on commit b66f8eb

Please sign in to comment.