Skip to content

Commit

Permalink
should get all the keys involved when creating the description (2600h…
Browse files Browse the repository at this point in the history
…z#4045)

* should get all the keys involved when creating the description

* don't halt, just output

* LC

* use default description where possible
  • Loading branch information
jamesaimonetti authored and fenollp committed Aug 8, 2017
1 parent 3244163 commit 4be0979
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core/kazoo_ast/src/kapps_config_usage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,19 @@ config_to_schema(Source, F, [Cat, K, Default, _Node], Schemas) ->
config_to_schema(Source, F, [Cat, K, Default], Schemas);
config_to_schema(Source, F, [Cat, K, Default], Schemas) ->
Document = category_to_document(Cat),

case key_to_key_path(K) of
'undefined' -> Schemas;
Key -> config_key_to_schema(Source, F, Document, Key, Default, Schemas)
Key ->
config_key_to_schema(Source, F, Document, Key, Default, Schemas)
end.

config_key_to_schema(_Source, _F, 'undefined', _Key, _Default, Schemas) ->
Schemas;
config_key_to_schema(Source, F, Document, Key, Default, Schemas) ->
Properties = guess_properties(Document, Source, Key, guess_type(F, Default), Default),
Path = [Document, ?FIELD_PROPERTIES | Key],

kz_json:set_value(Path, Properties, Schemas).

category_to_document(?VAR(_)) -> 'undefined';
Expand Down Expand Up @@ -287,15 +290,13 @@ guess_type_by_default(?MOD_FUN_ARGS('kz_binary', 'rand_hex', _Args)) -> <<"strin

guess_properties(Document, SourceModule, Key=?NE_BINARY, Type, Default) ->
DescriptionKey = description_key(Document, Key),
Description = fetch_description(DescriptionKey),
case undefined =:= Description of
false -> ok;
true ->
io:format("\nYou need to add the key \"~s\" in ~s\n"
,[DescriptionKey, ?SYSTEM_CONFIG_DESCRIPTIONS]
),
halt(1)
end,

Description =
case fetch_description(DescriptionKey) of
'undefined' ->
kz_binary:join(binary:split(DescriptionKey, <<".">>, ['global']), <<" ">>);
D -> D
end,
kz_json:from_list(
[{?SOURCE, SourceModule}
,{<<"description">>, Description}
Expand All @@ -306,10 +307,9 @@ guess_properties(Document, SourceModule, Key=?NE_BINARY, Type, Default) ->
guess_properties(Document, Source, [Key], Type, Default)
when is_binary(Key) ->
guess_properties(Document, Source, Key, Type, Default);
guess_properties(Document, Source, [Key, ?FIELD_PROPERTIES], Type, Default) ->
guess_properties(Document, Source, Key, Type, Default);
guess_properties(Document, Source, [_Key, ?FIELD_PROPERTIES | Rest], Type, Default) ->
guess_properties(Document, Source, Rest, Type, Default).
guess_properties(Document, Source, [_Key, ?FIELD_PROPERTIES|_]=Keys, Type, Default) ->
JustKeys = [K || K <- Keys, ?FIELD_PROPERTIES =/= K],
guess_properties(Document, Source, kz_binary:join(JustKeys, $.), Type, Default).

type([undefined]) ->
[{?FIELD_TYPE, <<"array">>}];
Expand Down

0 comments on commit 4be0979

Please sign in to comment.