Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support-empty-requests-and-responses #405

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/grpc/server/transcode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ defmodule GRPC.Server.Transcode do

defp map_request_body(%{body: "*"}, request_body), do: request_body
defp map_request_body(%{body: ""}, request_body), do: request_body

defp map_request_body(%{body: field}, request_body),
do: %{field => request_body}
defp map_request_body(%{body: field}, request_body), do: %{field => request_body}
defp map_request_body(%{}, request_body), do: request_body

@spec map_response_body(t() | map(), map()) :: map()
def map_response_body(%{response_body: ""}, response_body), do: response_body
Expand All @@ -70,6 +69,8 @@ defmodule GRPC.Server.Transcode do
Map.get(response_body, key)
end

def map_response_body(%{}, response_body), do: response_body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match on an empty map. It matches on any map. You need to use when map_size(arg) == 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please add tests for this


@spec map_path_bindings(map()) :: map()
def map_path_bindings(bindings) when bindings == %{}, do: bindings

Expand Down