Skip to content

Commit

Permalink
fix: compile protos with original names
Browse files Browse the repository at this point in the history
  • Loading branch information
sleipnir committed Aug 22, 2024
1 parent 23b07af commit 49b642f
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions lib/sidecar/grpc/generators/reflection_server_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,42 @@ defmodule Sidecar.Grpc.Generators.ReflectionServerGenerator do
end

@impl true
def generate(ctx, %Google.Protobuf.FileDescriptorProto{service: svcs} = _desc) do
def generate(ctx, %Google.Protobuf.FileDescriptorProto{name: name, service: svcs} = _desc) do
current_services = :persistent_term.get(:grpc_reflection_services, [])

services = do_generate(ctx, svcs, current_services)
{_name,
[
services: services
]} = result = do_generate(ctx, name, svcs, current_services)

:persistent_term.put(:grpc_reflection_services, services)

{List.first(services),
result
end

defp do_generate(_ctx, name, nil, current_services) do
{name,
[
services: services
services: current_services
]}
end

defp do_generate(_ctx, name, [], current_services) do
{name,
[
services: current_services
]}
end

defp do_generate(_ctx, nil, current_services), do: current_services
defp do_generate(_ctx, [], current_services), do: current_services
defp do_generate(ctx, _name, svcs, current_services) do
services =
svcs
|> Enum.map(fn svc -> Util.mod_name(ctx, [Macro.camelize(svc.name)]) end)
|> Kernel.++(current_services)

defp do_generate(ctx, svcs, current_services) do
svcs
|> Enum.map(fn svc -> Util.mod_name(ctx, [Macro.camelize(svc.name)]) end)
|> Kernel.++(current_services)
{List.first(services),
[
services: services
]}
end
end

0 comments on commit 49b642f

Please sign in to comment.