Skip to content

Commit 97298fd

Browse files
authored
Merge pull request #127 from aws-beam/add-atom-to-elixir-type-specs
Add Atom.t() to Elixir type specs so either String.t() or Atom.t() is accepted
2 parents 03c8dfe + f617eb0 commit 97298fd

5 files changed

Lines changed: 651 additions & 589 deletions

File tree

lib/aws_codegen/types.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ defmodule AWS.CodeGen.Types do
133133
end
134134

135135
# Unfortunately, gotta patch over auto-defining types that already exist in Elixir
136-
defp shape_to_type(:elixir, "String", _), do: "String.t()"
136+
defp shape_to_type(:elixir, "String", _), do: "String.t() | atom()"
137137
defp shape_to_type(:erlang, "String", _), do: "string()"
138-
defp shape_to_type(:elixir, "string", _), do: "String.t()"
138+
defp shape_to_type(:elixir, "string", _), do: "String.t() | atom()"
139139
defp shape_to_type(:erlang, "string", _), do: "string()"
140-
defp shape_to_type(:elixir, "Identifier", _), do: "String.t()"
140+
defp shape_to_type(:elixir, "Identifier", _), do: "String.t() | atom()"
141141
defp shape_to_type(:erlang, "Identifier", _), do: "string()"
142-
defp shape_to_type(:elixir, "identifier", _), do: "String.t()"
142+
defp shape_to_type(:elixir, "identifier", _), do: "String.t() | atom()"
143143
defp shape_to_type(:erlang, "identifier", _), do: "string()"
144-
defp shape_to_type(:elixir, "XmlString" <> _rest, _), do: "String.t()"
144+
defp shape_to_type(:elixir, "XmlString" <> _rest, _), do: "String.t() | atom()"
145145
defp shape_to_type(:erlang, "XmlString" <> _rest, _), do: "string"
146146
defp shape_to_type(:elixir, "NullablePositiveInteger", _), do: "nil | non_neg_integer()"
147147
defp shape_to_type(:erlang, "NullablePositiveInteger", _), do: "undefined | non_neg_integer()"
@@ -153,7 +153,7 @@ defmodule AWS.CodeGen.Types do
153153
defp shape_to_type(_, %Shape{type: "timestamp"}, _module_name), do: "non_neg_integer()"
154154
defp shape_to_type(_, %Shape{type: "map"}, _module_name), do: "map()"
155155
defp shape_to_type(_, %Shape{type: "blob"}, _module_name), do: "binary()"
156-
defp shape_to_type(:elixir, %Shape{type: "string"}, _module_name), do: "String.t()"
156+
defp shape_to_type(:elixir, %Shape{type: "string"}, _module_name), do: "String.t() | atom()"
157157
defp shape_to_type(:erlang, %Shape{type: "string"}, _module_name), do: "string()"
158158
defp shape_to_type(_, %Shape{type: "integer"}, _module_name), do: "integer()"
159159
defp shape_to_type(_, %Shape{type: "boolean"}, _module_name), do: "boolean()"
@@ -314,9 +314,9 @@ defmodule AWS.CodeGen.Types do
314314
parameters,
315315
fn parameter ->
316316
if not parameter.required do
317-
", String.t() | nil"
317+
", String.t() | atom() | nil"
318318
else
319-
", String.t()"
319+
", String.t() | atom()"
320320
end
321321
end
322322
)

priv/post.ex.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule <%= context.module_name %> do
2525
}
2626
<% end %>
2727
"""
28-
@type <%= if map_size(type_fields) == 0 do "#{type_name}() :: %{}" else "#{type_name}() :: %{String.t => any()}" end %>
28+
@type <%= if map_size(type_fields) == 0 do "#{type_name}() :: %{}" else "#{type_name}() :: %{(String.t() | atom()) => any()}" end %>
2929
<% end %>
3030

3131
<%= Enum.map(context.actions,

priv/rest.ex.eex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule <%= context.module_name %> do
2525
}
2626
<% end %>
2727
"""
28-
@type <%= if Enum.empty?(type_fields) do "#{type_name}() :: %{}" else "#{type_name}() :: %{String.t => any()}" end %>
28+
@type <%= if Enum.empty?(type_fields) do "#{type_name}() :: %{}" else "#{type_name}() :: %{(String.t() | atom()) => any()}" end %>
2929
<% end %>
3030

3131
<%= Enum.map(context.actions,
@@ -71,7 +71,7 @@ defmodule <%= context.module_name %> do
7171
@doc """
7272
<%= action.docstring %>
7373
"""<% end %><%= if action.method == "GET" do %>
74-
@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)%>
74+
@spec <%= action.function_name %>(map()<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>, String.t() | atom()<% end %><%= AWS.CodeGen.Types.function_parameter_types(action.method, action, false)%>, list()) :: <%= AWS.CodeGen.Types.return_type(context.language, action)%>
7575
def <%= action.function_name %>(%Client{} = client<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>, stage<% end %><%= AWS.CodeGen.RestService.function_parameters(action) %>, options \\ []) do
7676
url_path = "<%= if context.module_name == "AWS.ApiGatewayManagementApi" do %>/#{stage}<% end %><%= AWS.CodeGen.RestService.Action.url_path(action) %>"
7777
headers = []<%= for parameter <- action.request_header_parameters do %>
@@ -115,7 +115,7 @@ defmodule <%= context.module_name %> do
115115
<% end %>
116116

117117
Request.request_rest(client, meta, :get, url_path, query_params, headers, nil, options, <%= inspect(action.success_status_code) %>)<% else %>
118-
@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)%>
118+
@spec <%= action.function_name %>(map()<%= AWS.CodeGen.Types.function_parameter_types(action.method, action, false)%>, <%= if context.module_name == "AWS.ApiGatewayManagementApi" do %> String.t() | atom(), <% end %><%= AWS.CodeGen.Types.function_argument_type(context.language, action)%>, list()) :: <%= AWS.CodeGen.Types.return_type(context.language, action)%>
119119
def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.function_parameters(action) %>, <%= if context.module_name == "AWS.ApiGatewayManagementApi" do %> stage, <% end %>input, options \\ []) do
120120
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 %>
121121
{headers, input} =

0 commit comments

Comments
 (0)