refactor(schema): ensure roots/0 and namespace/0 for all schema modules

This commit is contained in:
Zaiming (Stone) Shi 2024-02-15 22:57:34 +01:00
parent a389d78b42
commit f57f617ba3
44 changed files with 150 additions and 49 deletions

View File

@ -42,7 +42,8 @@
-export([
api_spec/0,
paths/0,
schema/1
schema/1,
namespace/0
]).
-export([
@ -95,6 +96,8 @@
-elvis([{elvis_style, god_modules, disable}]).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -41,7 +41,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -56,6 +57,9 @@
-define(TAGS, [<<"Authorization">>]).
namespace() ->
undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -22,7 +22,8 @@
-export([
roots/0,
fields/1,
desc/1
desc/1,
namespace/0
]).
-export([
@ -65,6 +66,8 @@
roots() -> [].
namespace() -> undefined.
fields(?CONF_NS) ->
emqx_schema:authz_fields() ++ authz_fields();
fields("metrics_status_fields") ->

View File

@ -35,7 +35,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
%% operation funs
@ -69,6 +70,8 @@
-define(PUT_MAP_EXAMPLE, in_put_requestBody).
-define(POST_ARRAY_EXAMPLE, in_post_requestBody).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -13,7 +13,8 @@
examples/1,
resource_type/1,
bridge_impl_module/1,
fields/1
fields/1,
namespace/0
]).
api_schemas(Method) ->
@ -139,6 +140,8 @@ bridge_impl_module(azure_event_hub_producer) ->
bridge_impl_module(_BridgeType) ->
undefined.
namespace() -> undefined.
fields(bridges) ->
[
{hstreamdb,

View File

@ -14,7 +14,7 @@
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
%% schema
-export([roots/0, fields/1, desc/1]).
-export([roots/0, fields/1, desc/1, namespace/0]).
%% callbacks of behaviour emqx_resource
-export([
@ -56,6 +56,8 @@
%%--------------------------------------------------------------------
%% schema
namespace() -> cassandra.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -1,6 +1,6 @@
{application, emqx_bridge_clickhouse, [
{description, "EMQX Enterprise ClickHouse Bridge"},
{vsn, "0.2.4"},
{vsn, "0.2.5"},
{registered, []},
{applications, [
kernel,

View File

@ -23,7 +23,8 @@
-export([
roots/0,
fields/1,
values/1
values/1,
namespace/0
]).
%% callbacks for behaviour emqx_resource
@ -72,6 +73,8 @@
%% Configuration and default values
%%=====================================================================
namespace() -> clickhouse.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -1,6 +1,6 @@
{application, emqx_bridge_dynamo, [
{description, "EMQX Enterprise Dynamo Bridge"},
{vsn, "0.1.4"},
{vsn, "0.1.5"},
{registered, []},
{applications, [
kernel,

View File

@ -12,7 +12,7 @@
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-export([roots/0, fields/1]).
-export([roots/0, fields/1, namespace/0]).
%% `emqx_resource' API
-export([
@ -32,6 +32,9 @@
%%=====================================================================
%% Hocon schema
namespace() -> dynamodka.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -115,7 +115,8 @@ action_values() ->
%% -------------------------------------------------------------------------------------------------
%% Hocon Schema Definitions
namespace() -> "bridge_rocketmq".
namespace() -> "rocketmq".
roots() -> [].

View File

@ -12,7 +12,7 @@
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-export([roots/0, fields/1]).
-export([roots/0, fields/1, namespace/0]).
%% `emqx_resource' API
-export([
@ -36,6 +36,9 @@
%%=====================================================================
%% Hocon schema
namespace() -> rocketmq.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -1,6 +1,6 @@
{application, emqx_bridge_sqlserver, [
{description, "EMQX Enterprise SQL Server Bridge"},
{vsn, "0.1.5"},
{vsn, "0.1.6"},
{registered, []},
{applications, [kernel, stdlib, emqx_resource, odbc]},
{env, []},

View File

@ -24,7 +24,8 @@
%% Hocon config schema exports
-export([
roots/0,
fields/1
fields/1,
namespace/0
]).
%% callbacks for behaviour emqx_resource
@ -132,6 +133,8 @@
%% Configuration and default values
%%====================================================================
namespace() -> sqlserver.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -44,12 +44,6 @@
password/0
]).
-export([roots/0, fields/1]).
roots() -> [].
fields(_) -> [].
ssl_fields() ->
[
{ssl, #{

View File

@ -15,8 +15,8 @@
-export([
api_schemas/1,
fields/1,
%%examples/1
schema_modules/0
schema_modules/0,
namespace/0
]).
resource_type(Type) when is_binary(Type) ->
@ -93,6 +93,8 @@ connector_impl_module(rabbitmq) ->
connector_impl_module(_ConnectorType) ->
undefined.
namespace() -> undefined.
fields(connectors) ->
connector_structs().

View File

@ -27,7 +27,8 @@
-export([
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -35,6 +36,8 @@
monitor_current/2
]).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).

View File

@ -19,7 +19,7 @@
-behaviour(hocon_schema).
%% API
-export([paths/0, api_spec/0, schema/1, namespace/0, fields/1]).
-export([paths/0, api_spec/0, schema/1, roots/0, namespace/0, fields/1]).
-export([init_per_suite/1, end_per_suite/1]).
-export([t_in_path/1, t_in_query/1, t_in_mix/1, t_without_in/1, t_ref/1, t_public_ref/1]).
-export([t_require/1, t_query_enum/1, t_nullable/1, t_method/1, t_api_spec/1]).
@ -563,6 +563,7 @@ schema("/method/error") ->
#{operationId => test, bar => #{200 => <<"ok">>}}.
namespace() -> undefined.
roots() -> [].
fields(page) ->
[

View File

@ -17,9 +17,10 @@
-include_lib("typerefl/include/types.hrl").
-export([roots/0, fields/1]).
-export([namespace/0, roots/0, fields/1]).
-import(hoconsc, [mk/2]).
roots() -> ["root"].
namespace() -> undefined.
fields("root") ->
[

View File

@ -813,7 +813,8 @@ to_schema(Body) ->
post => #{requestBody => Body, responses => #{200 => <<"ok">>}}
}.
%% Don't warning hocon callback namespace/0 undef.
roots() -> [].
namespace() -> atom_to_list(?MODULE).
fields(good_ref) ->

View File

@ -680,6 +680,7 @@ to_schema(Object) ->
post => #{responses => #{200 => Object, 201 => Object}}
}.
rotos() -> [].
namespace() -> undefined.
fields(good_ref) ->

View File

@ -36,7 +36,8 @@
-export([
api_spec/0,
paths/0,
schema/1
schema/1,
namespace/0
]).
-export([
@ -59,6 +60,8 @@
%% minirest behaviour callbacks
%%--------------------------------------------------------------------
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -42,7 +42,8 @@
-export([
roots/0,
fields/1
fields/1,
namespace/0
]).
%% http handlers
@ -775,6 +776,8 @@ schema_client() ->
examples_client()
).
namespace() -> undefined.
roots() ->
[
stomp_client,

View File

@ -45,7 +45,8 @@
-export([
roots/0,
fields/1
fields/1,
namespace/0
]).
%% http handlers
@ -651,6 +652,9 @@ params_paging_in_qs() ->
%%--------------------------------------------------------------------
%% schemas
namespace() ->
undefined.
roots() ->
[listener].

View File

@ -9,10 +9,12 @@
-include_lib("typerefl/include/types.hrl").
-behaviour(hocon_schema).
-export([namespace/0, fields/1, desc/1]).
-export([roots/0, namespace/0, fields/1, desc/1]).
-define(NOT_EMPTY(MSG), emqx_resource_validator:not_empty(MSG)).
roots() -> [].
namespace() -> gateway.
fields(jt808) ->

View File

@ -1,6 +1,6 @@
{application, emqx_gcp_device, [
{description, "Application simplifying migration from GCP IoT Core"},
{vsn, "0.1.3"},
{vsn, "0.1.4"},
{registered, []},
{mod, {emqx_gcp_device_app, []}},
{applications, [

View File

@ -22,7 +22,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -62,6 +63,9 @@
%% `minirest' and `minirest_trails' API
%%-------------------------------------------------------------------------------------------------
namespace() ->
undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -22,7 +22,7 @@
-include_lib("emqx/include/emqx.hrl").
-include_lib("typerefl/include/types.hrl").
-export([api_spec/0, paths/0, schema/1, fields/1]).
-export([api_spec/0, paths/0, schema/1, fields/1, namespace/0]).
-export([alarms/2, format_alarm/2]).
@ -31,6 +31,9 @@
%% internal export (for query)
-export([qs2ms/2]).
namespace() ->
undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -28,7 +28,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([format/1]).
@ -44,6 +45,9 @@
-define(FORMAT_FUN, {?MODULE, format}).
namespace() ->
undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).

View File

@ -32,7 +32,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -83,6 +84,8 @@
message => <<"Client ID not found">>
}).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).

View File

@ -21,7 +21,7 @@
-include_lib("emqx/include/logger.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-export([api_spec/0, paths/0, schema/1, fields/1]).
-export([api_spec/0, paths/0, schema/1, fields/1, namespace/0]).
-export([
data_export/2,
@ -48,6 +48,8 @@
})}
).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -27,7 +27,8 @@
-export([
api_spec/0,
paths/0,
schema/1
schema/1,
namespace/0
]).
-export([
@ -42,6 +43,8 @@
%% minirest behaviour callbacks
%%--------------------------------------------------------------------
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -30,7 +30,8 @@
api_spec/0,
schema/1,
paths/0,
fields/1
fields/1,
namespace/0
]).
%% API callbacks
@ -45,6 +46,8 @@
%% API spec funcs
%%--------------------------------------------------------------------
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -32,7 +32,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -40,6 +41,8 @@
publish_batch/2
]).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).

View File

@ -34,11 +34,14 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([list/2]).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -28,7 +28,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([subscriptions/2]).
@ -48,6 +49,9 @@
{<<"match_topic">>, binary}
]).
namespace() ->
undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -28,7 +28,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -41,6 +42,8 @@
-define(TOPICS_QUERY_SCHEMA, [{<<"topic">>, binary}, {<<"node">>, atom}]).
-define(TAGS, [<<"Topics">>]).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).

View File

@ -34,7 +34,8 @@
-export([
paths/0,
fields/1,
schema/1
schema/1,
namespace/0
]).
%% for rpc
@ -55,6 +56,8 @@
-define(INVALID_TOPIC, 'INVALID_TOPIC_NAME').
-define(MESSAGE_NOT_FOUND, 'MESSAGE_NOT_FOUND').
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -47,7 +47,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-define(EXCEED_LIMIT, 'EXCEED_LIMIT').
@ -55,6 +56,8 @@
-define(TOPIC_NOT_FOUND, 'TOPIC_NOT_FOUND').
-define(BAD_REQUEST, 'BAD_REQUEST').
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -44,7 +44,7 @@
unprepare_sql/1
]).
-export([roots/0, fields/1]).
-export([roots/0, fields/1, namespace/0]).
-export([do_get_status/1]).
@ -63,6 +63,9 @@
-export_type([state/0]).
%%=====================================================================
%% Hocon schema
namespace() -> mysql.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -12,9 +12,12 @@
%% Hocon config schema exports
-export([
roots/0,
fields/1
fields/1,
namespace/0
]).
namespace() -> oracle.
roots() ->
[{config, #{type => hoconsc:ref(?REF_MODULE, config)}}].

View File

@ -23,7 +23,7 @@
-include_lib("epgsql/include/epgsql.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-export([roots/0, fields/1]).
-export([roots/0, fields/1, namespace/0]).
-behaviour(emqx_resource).
@ -71,6 +71,8 @@
%%=====================================================================
namespace() -> postgres.
roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

View File

@ -34,7 +34,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-export([
@ -50,6 +51,8 @@
-define(IS_TRUE(Val), ((Val =:= true) orelse (Val =:= <<"true">>))).
-define(IS_FALSE(Val), ((Val =:= false) orelse (Val =:= <<"false">>))).
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

View File

@ -32,12 +32,15 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).
-define(BAD_REQUEST, 'BAD_REQUEST').
-define(NOT_FOUND, 'NOT_FOUND').
namespace() -> undefined.
api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).