Skip to content

Commit 6ff3635

Browse files
authored
Merge pull request #383 from sleipnir/ref/remove-warnings
Remove warnings
2 parents 55f5d1a + 2cda1e3 commit 6ff3635

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

lib/grpc/codec/json.ex

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,73 @@
1-
defmodule GRPC.Codec.JSON do
2-
@moduledoc """
3-
JSON Codec for gRPC communication.
1+
if Code.ensure_loaded?(Jason) do
2+
defmodule GRPC.Codec.JSON do
3+
@moduledoc """
4+
JSON Codec for gRPC communication.
45
5-
This module implements the `GRPC.Codec` behaviour, providing encoding and decoding functions
6-
for JSON serialization in the context of gRPC communication.
6+
This module implements the `GRPC.Codec` behaviour, providing encoding and decoding functions
7+
for JSON serialization in the context of gRPC communication.
78
8-
## Behavior Functions
9+
## Behavior Functions
910
10-
- `name/0`: Returns the name of the codec, which is "json".
11-
- `encode/1`: Encodes a struct using the Protobuf.JSON.encode!/1 function.
12-
- `decode/2`: Decodes binary data into a map using the Jason library.
11+
- `name/0`: Returns the name of the codec, which is "json".
12+
- `encode/1`: Encodes a struct using the Protobuf.JSON.encode!/1 function.
13+
- `decode/2`: Decodes binary data into a map using the Jason library.
1314
14-
This module requires the Jason dependency.
15-
"""
16-
@behaviour GRPC.Codec
15+
This module requires the Jason dependency.
16+
"""
17+
@behaviour GRPC.Codec
1718

18-
def name(), do: "json"
19+
def name(), do: "json"
1920

20-
@doc """
21-
Encodes a struct using the Protobuf.JSON.encode!/1 function.
21+
@doc """
22+
Encodes a struct using the Protobuf.JSON.encode!/1 function.
2223
23-
### Parameters:
24+
### Parameters:
2425
25-
- `struct` - The struct to be encoded.
26+
- `struct` - The struct to be encoded.
2627
27-
### Returns:
28+
### Returns:
2829
29-
The encoded binary data.
30+
The encoded binary data.
3031
31-
### Example:
32+
### Example:
3233
33-
```elixir
34-
%MyStruct{id: 1, name: "John"} |> GRPC.Codec.JSON.encode()
35-
```
34+
```elixir
35+
%MyStruct{id: 1, name: "John"} |> GRPC.Codec.JSON.encode()
36+
```
3637
37-
"""
38+
"""
3839

39-
def encode(struct) do
40-
Protobuf.JSON.encode!(struct)
41-
end
40+
def encode(struct) do
41+
Protobuf.JSON.encode!(struct)
42+
end
4243

43-
@doc """
44-
Decodes binary data into a map using the Jason library.
45-
Parameters:
44+
@doc """
45+
Decodes binary data into a map using the Jason library.
46+
Parameters:
4647
47-
binary - The binary data to be decoded.
48-
module - Module to be created.
48+
binary - The binary data to be decoded.
49+
module - Module to be created.
4950
50-
Returns:
51+
Returns:
5152
52-
A map representing the decoded data.
53+
A map representing the decoded data.
5354
54-
Raises:
55+
Raises:
5556
56-
Raises an error if the Jason library is not loaded.
57+
Raises an error if the Jason library is not loaded.
5758
58-
Example:
59+
Example:
5960
60-
```elixir
61-
binary_data |> GRPC.Codec.JSON.decode(__MODULE__)
62-
```
63-
"""
64-
def decode(<<>>, _module), do: %{}
61+
```elixir
62+
binary_data |> GRPC.Codec.JSON.decode(__MODULE__)
63+
```
64+
"""
65+
def decode(<<>>, _module), do: %{}
6566

66-
def decode(binary, _module), do: Jason.decode!(binary)
67+
def decode(binary, _module), do: Jason.decode!(binary)
68+
end
69+
else
70+
defmodule GRPC.Codec.JSON do
71+
def decode(_, _), do: raise(ArgumentError, "Module Jason not found")
72+
end
6773
end

lib/grpc/protoc/generator/service.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule GRPC.Protoc.Generator.Service do
3636
methods: methods,
3737
descriptor_fun_body: descriptor_fun_body,
3838
version: Util.version(),
39-
module_doc?: ctx.include_docs?
39+
module_doc?: false
4040
)
4141
)}
4242
end

test/grpc/integration/server_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ defmodule GRPC.Integration.ServerTest do
377377

378378
test "should map grpc error codes to http status" do
379379
run_server([TranscodeErrorServer], fn port ->
380-
for {code_name, status} <- [
380+
for {code_name, _status} <- [
381381
{"cancelled", 400},
382382
{"unknown", 500},
383383
{"invalid_argument", 400},
@@ -397,7 +397,7 @@ defmodule GRPC.Integration.ServerTest do
397397
] do
398398
{:ok, conn_pid} = :gun.open(~c"localhost", port)
399399

400-
stream_ref =
400+
_stream_ref =
401401
:gun.get(
402402
conn_pid,
403403
"/v1/messages/#{code_name}",

0 commit comments

Comments
 (0)