Skip to content

Commit 36344d2

Browse files
committed
Remove warnings
1 parent 7dc28cd commit 36344d2

File tree

4 files changed

+53
-47
lines changed

4 files changed

+53
-47
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
@@ -346,7 +346,7 @@ defmodule GRPC.Integration.ServerTest do
346346

347347
test "should map grpc error codes to http status" do
348348
run_server([TranscodeErrorServer], fn port ->
349-
for {code_name, status} <- [
349+
for {code_name, _status} <- [
350350
{"cancelled", 400},
351351
{"unknown", 500},
352352
{"invalid_argument", 400},
@@ -366,7 +366,7 @@ defmodule GRPC.Integration.ServerTest do
366366
] do
367367
{:ok, conn_pid} = :gun.open(~c"localhost", port)
368368

369-
stream_ref =
369+
_stream_ref =
370370
:gun.get(
371371
conn_pid,
372372
"/v1/messages/#{code_name}",

test/grpc/integration/stub_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule GRPC.Integration.StubTest do
6969
end
7070

7171
test "invalid channel function clause error" do
72-
req = Helloworld.HelloRequest.new(name: "GRPC")
72+
req = %Helloworld.HelloRequest{name: "GRPC"}
7373

7474
assert_raise FunctionClauseError, ~r/Helloworld.Greeter.Stub.say_hello/, fn ->
7575
Helloworld.Greeter.Stub.say_hello(nil, req)

0 commit comments

Comments
 (0)