aws-beam / aws-codegen

Code generator for AWS clients in Erlang and Elixir.
Other
53 stars 49 forks source link

Fix return value of HEAD requests and fix type spec of request/8 #78

Closed onno-vos-dev closed 3 years ago

onno-vos-dev commented 3 years ago

This actually showed up due to Dialyzer indicating us that this was wrong in our code. Even if Dialyzer was run (which it isn't) on aws-erlang it may or may not have caught it since a catch-all type of clause exists there.

Diff that it generates for aws_s3

diff --git a/src/aws_s3.erl b/src/aws_s3.erl
index 430212f..8829dde 100644
--- a/src/aws_s3.erl
+++ b/src/aws_s3.erl
@@ -3760,7 +3760,8 @@ head_object(Client, Bucket, Key, Input0, Options0) ->
                    ],
     {Query_, Input} = aws_request:build_headers(QueryMapping, Input2),
     case request(Client, Method, Path, Query_, CustomHeaders ++ Headers, Input, Options, SuccessStatusCode) of
-      {ok, Body0, {_, ResponseHeaders, _} = Response} ->
+      {ok, {_, ResponseHeaders} = Response} ->
+        Body0 = #{},
         ResponseHeadersParams =
           [
             {<<"accept-ranges">>, <<"AcceptRanges">>},
@@ -7407,6 +7408,7 @@ write_get_object_response(Client, Input0, Options0) ->

 -spec request(aws_client:aws_client(), atom(), iolist(), list(),
               list(), map() | undefined, list(), pos_integer() | undefined) ->
+    {ok, {integer(), list()}} |
     {ok, Result, {integer(), list(), hackney:client()}} |
     {error, Error, {integer(), list(), hackney:client()}} |
     {error, term()} when
onno-vos-dev commented 3 years ago

Since this shrank the diff even more, I squashed it into the original commit. Hope you don't mind :-)

Re-running the following produces no diff so semantically both changes are the same:

export SPEC_PATH=../aws-sdk-go/models/apis
export TEMPLATE_PATH=priv
export ERLANG_OUTPUT_PATH=../aws-erlang/src
mix run generate.exs erlang $SPEC_PATH $TEMPLATE_PATH $ERLANG_OUTPUT_PATH
jfacorro commented 3 years ago

Thank you for the contribution 😄