Skip to content

Commit b99bd9e

Browse files
committed
refactor: make namespace/0 a non-optional export
1 parent 3912cae commit b99bd9e

12 files changed

+23
-16
lines changed

Diff for: sample-schemas/demo_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
-reflect_type([duration/0, percent/0]).
1616

17-
-export([roots/0, fields/1, translations/0, translation/1]).
17+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
1818

1919
-define(FIELD(NAME, TYPE), hoconsc:mk(TYPE, #{mapping => NAME})).
2020

21+
namespace() -> "demo".
2122
roots() -> [foo, {"a_b", hoconsc:mk(hoconsc:ref("a_b"), #{importance => hidden})}, "b", person, "vm"].
2223
translations() -> ["app_foo"].
2324

Diff for: sample-schemas/emqx_auth_http_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

9+
namespace() -> "auth_http".
910
roots() -> ["auth"].
1011

1112
fields("auth") ->

Diff for: sample-schemas/emqx_auth_jwt_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

9+
namespace() -> "auth_jwt".
910
roots() -> ["auth"].
1011

1112
fields("auth") ->

Diff for: sample-schemas/emqx_auth_ldap_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

9+
namespace() -> "auth_ldap".
910
roots() -> ["auth"].
1011

1112
fields("auth") ->

Diff for: sample-schemas/emqx_auth_mnesia_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

9+
namespace() -> "auth_mnesia".
910
roots() -> ["auth"].
1011

1112
fields("auth") ->

Diff for: sample-schemas/emqx_auth_mongo_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
-reflect_type([type/0, w_mode/0, r_mode/0]).
1313

14-
-export([roots/0, fields/1, translations/0, translation/1]).
14+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
1515

16+
namespace() -> "auth_mongo".
1617
roots() -> ["auth"].
1718

1819
fields("auth") ->

Diff for: sample-schemas/emqx_auth_mysql_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

99
roots() -> ["auth"].
1010

11+
namespace() -> "auth_mysql".
1112
fields("auth") ->
1213
[ {"mysql", emqx_schema:ref("mysql")}];
1314

Diff for: sample-schemas/emqx_auth_pgsql_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

9+
namespace() -> "auth_pgsql".
910
roots() -> ["auth"].
1011

1112
fields("auth") ->

Diff for: sample-schemas/emqx_auth_redis_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
-behaviour(hocon_schema).
66

7-
-export([roots/0, fields/1, translations/0, translation/1]).
7+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
88

9+
namespace() -> "auth_redis".
910
roots() -> ["auth"].
1011

1112
fields("auth") ->

Diff for: sample-schemas/emqx_management_schema.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
-reflect_type([endpoint/0, verify/0]).
1111

12-
-export([roots/0, fields/1, translations/0, translation/1]).
12+
-export([roots/0, fields/1, translations/0, translation/1, namespace/0]).
1313

14+
namespace() -> "management".
1415
roots() -> ["management"].
1516

1617
fields("management") ->

Diff for: src/hocon_schema.erl

+1-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
-callback tags() -> [tag()].
7575

7676
-optional_callbacks([
77-
roots/0,
7877
translations/0,
7978
translation/1,
8079
validations/0,
@@ -226,10 +225,7 @@ override(Base, OnTop) ->
226225
namespace(Schema) ->
227226
case is_atom(Schema) of
228227
true ->
229-
case erlang:function_exported(Schema, namespace, 0) of
230-
true -> Schema:namespace();
231-
false -> undefined
232-
end;
228+
Schema:namespace();
233229
false ->
234230
maps:get(namespace, Schema, undefined)
235231
end.

Diff for: test/hocon_tconf_tests.erl

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
-include("hocon_private.hrl").
2121
-include("hoconsc.hrl").
2222

23-
-export([roots/0, fields/1, validations/0, desc/1]).
23+
-export([roots/0, fields/1, validations/0, desc/1, namespace/0]).
2424

2525
-define(GEN_VALIDATION_ERR(Reason, Expr),
2626
?_assertThrow({_, [Reason]}, Expr)
@@ -29,6 +29,7 @@
2929
?assertThrow({_, [Reason]}, Expr)
3030
).
3131

32+
namespace() -> bar.
3233
roots() -> [bar].
3334

3435
fields(bar) ->

0 commit comments

Comments
 (0)