fix(influxdb): api schema `write_syntax` using raw type `string()`

This commit is contained in:
JimMoen 2022-08-11 11:35:04 +08:00
parent 0090a3ee93
commit 223b84017e
2 changed files with 15 additions and 3 deletions

View File

@ -656,6 +656,13 @@ typename_to_spec("file()", _Mod) ->
#{type => string, example => <<"/path/to/file">>}; #{type => string, example => <<"/path/to/file">>};
typename_to_spec("ip_port()", _Mod) -> typename_to_spec("ip_port()", _Mod) ->
#{type => string, example => <<"127.0.0.1:80">>}; #{type => string, example => <<"127.0.0.1:80">>};
typename_to_spec("write_syntax()", _Mod) ->
#{
type => string,
example =>
<<"${topic},clientid=${clientid}", " ", "payload=${payload},",
"${clientid}_int_value=${payload.int_key}i,", "bool=${payload.bool}">>
};
typename_to_spec("ip_ports()", _Mod) -> typename_to_spec("ip_ports()", _Mod) ->
#{type => string, example => <<"127.0.0.1:80, 127.0.0.2:80">>}; #{type => string, example => <<"127.0.0.1:80, 127.0.0.2:80">>};
typename_to_spec("url()", _Mod) -> typename_to_spec("url()", _Mod) ->

View File

@ -21,6 +21,11 @@
desc/1 desc/1
]). ]).
-type write_syntax() :: list().
-reflect_type([write_syntax/0]).
-typerefl_from_string({write_syntax/0, ?MODULE, to_influx_lines}).
-export([to_influx_lines/1]).
%% ------------------------------------------------------------------------------------------------- %% -------------------------------------------------------------------------------------------------
%% api %% api
@ -148,19 +153,19 @@ desc(_) ->
undefined. undefined.
write_syntax(type) -> write_syntax(type) ->
list(); ?MODULE:write_syntax();
write_syntax(required) -> write_syntax(required) ->
true; true;
write_syntax(validator) -> write_syntax(validator) ->
[?NOT_EMPTY("the value of the field 'write_syntax' cannot be empty")]; [?NOT_EMPTY("the value of the field 'write_syntax' cannot be empty")];
write_syntax(converter) -> write_syntax(converter) ->
fun converter_influx_lines/1; fun to_influx_lines/1;
write_syntax(desc) -> write_syntax(desc) ->
?DESC("write_syntax"); ?DESC("write_syntax");
write_syntax(_) -> write_syntax(_) ->
undefined. undefined.
converter_influx_lines(RawLines) -> to_influx_lines(RawLines) ->
Lines = string:tokens(str(RawLines), "\n"), Lines = string:tokens(str(RawLines), "\n"),
lists:reverse(lists:foldl(fun converter_influx_line/2, [], Lines)). lists:reverse(lists:foldl(fun converter_influx_line/2, [], Lines)).