mirror of
https://github.com/valitydev/elixir-thrift.git
synced 2024-11-07 02:35:17 +00:00
parent
67a85df415
commit
f2cb210282
@ -9,9 +9,12 @@ defmodule Thrift.Generator.Behaviour do
|
||||
alias Thrift.Generator.Utils
|
||||
alias Thrift.Parser.FileGroup
|
||||
alias Thrift.Parser.Models.{
|
||||
Exception,
|
||||
Field,
|
||||
Struct,
|
||||
StructRef,
|
||||
TEnum,
|
||||
Union,
|
||||
}
|
||||
|
||||
def generate(schema, service) do
|
||||
@ -65,6 +68,23 @@ defmodule Thrift.Generator.Behaviour do
|
||||
|> FileGroup.resolve(ref)
|
||||
|> typespec(file_group)
|
||||
end
|
||||
defp typespec(%TEnum{}, _) do
|
||||
quote do
|
||||
non_neg_integer
|
||||
end
|
||||
end
|
||||
defp typespec(%Union{name: name}, file_group) do
|
||||
dest_module = FileGroup.dest_module(file_group, name)
|
||||
quote do
|
||||
%unquote(dest_module){}
|
||||
end
|
||||
end
|
||||
defp typespec(%Exception{name: name}, file_group) do
|
||||
dest_module = FileGroup.dest_module(file_group, name)
|
||||
quote do
|
||||
%unquote(dest_module){}
|
||||
end
|
||||
end
|
||||
defp typespec(%Struct{name: name}, file_group) do
|
||||
dest_module = FileGroup.dest_module(file_group, name)
|
||||
quote do
|
||||
|
@ -6,6 +6,25 @@ defmodule BehaviourTest do
|
||||
1: string username
|
||||
}
|
||||
|
||||
struct T {
|
||||
1: i64 id
|
||||
}
|
||||
|
||||
union SorT {
|
||||
1: S s_value,
|
||||
2: T t_value
|
||||
}
|
||||
|
||||
enum WaitStates {
|
||||
WAITING
|
||||
ACCEPTING
|
||||
BLOCKED
|
||||
}
|
||||
|
||||
exception MyEx {
|
||||
1: string message
|
||||
}
|
||||
|
||||
service BehaviourService {
|
||||
void ping(1: i64 my_int),
|
||||
void my_bool(1: bool my_bool),
|
||||
@ -16,6 +35,9 @@ defmodule BehaviourTest do
|
||||
map<string, bool> my_map2(1: map<string, map<string, string>> my_map)
|
||||
void struct_param(1: S my_struct)
|
||||
void myCamelCasedFunction(1: string camelParam);
|
||||
WaitStates get_state();
|
||||
SorT get_s_or_t();
|
||||
MyEx dont_do_this();
|
||||
}
|
||||
"""
|
||||
|
||||
@ -31,5 +53,8 @@ defmodule BehaviourTest do
|
||||
assert {:my_map2, 1} in behaviour_specs
|
||||
assert {:struct_param, 1} in behaviour_specs
|
||||
assert {:my_camel_cased_function, 1} in behaviour_specs
|
||||
assert {:get_state, 0} in behaviour_specs
|
||||
assert {:get_s_or_t, 0} in behaviour_specs
|
||||
assert {:dont_do_this, 0} in behaviour_specs
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user