Skip to content

Commit 643d443

Browse files
committed
Generate types and type specs for all generated functions in aws-elixir and aws-erlang
- Generate common errors in order to unify types and reduce noise - Ensure that for Elixir, typedoc examples are considered code blocks - Erlang Type docs are not hoverable for now due to issues with 'rebar3 ex_doc' - Will follow up on this task - Increase Task.await/2 timeout
1 parent 6ba75a2 commit 643d443

File tree

12 files changed

+981
-125
lines changed

12 files changed

+981
-125
lines changed

lib/aws_codegen.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ defmodule AWS.CodeGen do
3333
protocol: nil,
3434
signature_version: nil,
3535
service_id: nil,
36+
shapes: %{},
3637
signing_name: nil,
3738
target_prefix: nil
3839
end
@@ -96,7 +97,7 @@ defmodule AWS.CodeGen do
9697
end
9798
)
9899

99-
Enum.each(tasks, fn task -> Task.await(task, 60_000) end)
100+
Enum.each(tasks, fn task -> Task.await(task, 120_000) end)
100101
end
101102

102103
defp generate_code(spec, language, endpoints_spec, template_base_path, output_path) do

lib/aws_codegen/post_service.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
defmodule AWS.CodeGen.PostService do
22
alias AWS.CodeGen.Docstring
33
alias AWS.CodeGen.Service
4+
alias AWS.CodeGen.Shapes
45

56
defmodule Action do
67
defstruct arity: nil,
78
docstring: nil,
89
function_name: nil,
10+
input: nil,
11+
output: nil,
12+
errors: %{},
913
host_prefix: nil,
1014
name: nil
1115
end
@@ -57,6 +61,7 @@ defmodule AWS.CodeGen.PostService do
5761
service = spec.api["shapes"][spec.shape_name]
5862
traits = service["traits"]
5963
actions = collect_actions(language, spec.api)
64+
shapes = Shapes.collect_shapes(language, spec.api)
6065
endpoint_prefix = traits["aws.api#service"]["endpointPrefix"] || traits["aws.api#service"]["arnNamespace"]
6166
endpoint_info = endpoints_spec["services"][endpoint_prefix]
6267
is_global = not is_nil(endpoint_info) and not Map.get(endpoint_info, "isRegionalized", true)
@@ -89,6 +94,7 @@ defmodule AWS.CodeGen.PostService do
8994
language: language,
9095
module_name: spec.module_name,
9196
protocol: protocol |> to_string() |> String.replace("_", "-"),
97+
shapes: shapes,
9298
signing_name: signing_name,
9399
signature_version: AWS.CodeGen.Util.get_signature_version(service),
94100
service_id: AWS.CodeGen.Util.get_service_id(service),
@@ -137,10 +143,14 @@ defmodule AWS.CodeGen.PostService do
137143
),
138144
function_name: AWS.CodeGen.Name.to_snake_case(operation),
139145
host_prefix: operation_spec["traits"]["smithy.api#endpoint"]["hostPrefix"],
140-
name: String.replace(operation, ~r/com\.amazonaws\.[^#]+#/, "")
146+
name: String.replace(operation, ~r/com\.amazonaws\.[^#]+#/, ""),
147+
input: operation_spec["input"],
148+
output: operation_spec["output"],
149+
errors: operation_spec["errors"]
141150
}
142151
end)
143152
|> Enum.sort(fn a, b -> a.function_name < b.function_name end)
144153
|> Enum.uniq()
145154
end
155+
146156
end

lib/aws_codegen/rest_service.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ defmodule AWS.CodeGen.RestService do
2323
send_body_as_binary?: false,
2424
receive_body_as_binary?: false,
2525
host_prefix: nil,
26-
language: nil
26+
language: nil,
27+
input: nil,
28+
output: nil,
29+
errors: []
2730

2831
def method(action) do
2932
result = action.method |> String.downcase() |> String.to_atom()
@@ -145,7 +148,8 @@ defmodule AWS.CodeGen.RestService do
145148
signing_name: signing_name,
146149
signature_version: AWS.CodeGen.Util.get_signature_version(service),
147150
service_id: AWS.CodeGen.Util.get_service_id(service),
148-
target_prefix: nil, ##TODO: metadata["targetPrefix"]
151+
target_prefix: nil, ##TODO: metadata["targetPrefix"],
152+
shapes: Shapes.collect_shapes(language, spec.api)
149153
}
150154
end
151155

@@ -275,7 +279,10 @@ defmodule AWS.CodeGen.RestService do
275279
send_body_as_binary?: Shapes.body_as_binary?(shapes, input_shape),
276280
receive_body_as_binary?: Shapes.body_as_binary?(shapes, output_shape),
277281
host_prefix: operation_spec["traits"]["smithy.api#endpoint"]["hostPrefix"],
278-
language: language
282+
language: language,
283+
input: operation_spec["input"],
284+
output: operation_spec["output"],
285+
errors: operation_spec["errors"]
279286
}
280287
end)
281288
|> Enum.sort(fn a, b -> a.function_name < b.function_name end)

lib/aws_codegen/shapes.ex

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
defmodule AWS.CodeGen.Shapes do
2-
@moduledoc false
2+
3+
defmodule Shape do
4+
defstruct name: nil,
5+
type: nil,
6+
members: [],
7+
member: [],
8+
enum: [],
9+
min: nil,
10+
required: [],
11+
is_input: nil
12+
end
313

414
def get_input_shape(operation_spec) do
515
get_in(operation_spec, ["input", "target"])
@@ -9,6 +19,22 @@ defmodule AWS.CodeGen.Shapes do
919
get_in(operation_spec, ["output", "target"])
1020
end
1121

22+
def collect_shapes(_language, api_spec) do
23+
api_spec["shapes"]
24+
|> Map.new(fn {name, shape} ->
25+
{name,
26+
%Shape{
27+
name: name,
28+
type: shape["type"],
29+
member: shape["member"],
30+
members: shape["members"],
31+
min: shape["min"],
32+
enum: shape["enum"],
33+
is_input: is_input?(shape)
34+
}}
35+
end)
36+
end
37+
1238
def body_as_binary?(shapes, shape) do
1339
## TODO: Should we validate or search for trait `smithy.api#httpPayload` rather than
1440
## trust that the member is always named `Body`?
@@ -23,4 +49,8 @@ defmodule AWS.CodeGen.Shapes do
2349
end
2450
end
2551

52+
def is_input?(shape) do
53+
!Map.has_key?(shape, "traits") or Map.has_key?(shape["traits"], "smithy.api#input")
54+
end
55+
2656
end

0 commit comments

Comments
 (0)