Skip to content

Commit

Permalink
Merge pull request #12517 from zmstone/0213-hocon-multiline-string-wi…
Browse files Browse the repository at this point in the history
…th-indentation

0213 hocon multiline string with indentation
  • Loading branch information
zmstone committed Feb 16, 2024
2 parents 497f631 + f57f617 commit 2b46cba
Show file tree
Hide file tree
Showing 51 changed files with 168 additions and 709 deletions.
2 changes: 1 addition & 1 deletion apps/emqx/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{esockd, {git, "https://github.com/emqx/esockd", {tag, "5.11.1"}}},
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.18.4"}}},
{gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.3.1"}}},
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.40.4"}}},
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.41.0"}}},
{emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.5.3"}}},
{pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}},
{recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}},
Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_auth/src/emqx_authn/emqx_authn_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
-export([
api_spec/0,
paths/0,
schema/1
schema/1,
namespace/0
]).

-export([
Expand Down Expand Up @@ -95,6 +96,8 @@

-elvis([{elvis_style, god_modules, disable}]).

namespace() -> undefined.

api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

Expand Down
6 changes: 5 additions & 1 deletion apps/emqx_auth/src/emqx_authz/emqx_authz_api_sources.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).

-export([
Expand All @@ -56,6 +57,9 @@

-define(TAGS, [<<"Authorization">>]).

namespace() ->
undefined.

api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_auth/src/emqx_authz/emqx_authz_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
-export([
roots/0,
fields/1,
desc/1
desc/1,
namespace/0
]).

-export([
Expand Down Expand Up @@ -65,6 +66,8 @@

roots() -> [].

namespace() -> undefined.

fields(?CONF_NS) ->
emqx_schema:authz_fields() ++ authz_fields();
fields("metrics_status_fields") ->
Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_auth_mnesia/src/emqx_authz_api_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
api_spec/0,
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).

%% operation funs
Expand Down Expand Up @@ -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}).

Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_bridge/src/schema/emqx_bridge_enterprise.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
examples/1,
resource_type/1,
bridge_impl_module/1,
fields/1
fields/1,
namespace/0
]).

api_schemas(Method) ->
Expand Down Expand Up @@ -139,6 +140,8 @@ bridge_impl_module(azure_event_hub_producer) ->
bridge_impl_module(_BridgeType) ->
undefined.

namespace() -> undefined.

fields(bridges) ->
[
{hstreamdb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -56,6 +56,8 @@
%%--------------------------------------------------------------------
%% schema

namespace() -> cassandra.

roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, emqx_bridge_clickhouse, [
{description, "EMQX Enterprise ClickHouse Bridge"},
{vsn, "0.2.4"},
{vsn, "0.2.5"},
{registered, []},
{applications, [
kernel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
-export([
roots/0,
fields/1,
values/1
values/1,
namespace/0
]).

%% callbacks for behaviour emqx_resource
Expand Down Expand Up @@ -72,6 +73,8 @@
%% Configuration and default values
%%=====================================================================

namespace() -> clickhouse.

roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

Expand Down
2 changes: 1 addition & 1 deletion apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, emqx_bridge_dynamo, [
{description, "EMQX Enterprise Dynamo Bridge"},
{vsn, "0.1.4"},
{vsn, "0.1.5"},
{registered, []},
{applications, [
kernel,
Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_bridge_dynamo/src/emqx_bridge_dynamo_connector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -32,6 +32,9 @@

%%=====================================================================
%% Hocon schema

namespace() -> dynamodka.

roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_bridge_rocketmq/src/emqx_bridge_rocketmq.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ action_values() ->

%% -------------------------------------------------------------------------------------------------
%% Hocon Schema Definitions
namespace() -> "bridge_rocketmq".

namespace() -> "rocketmq".

roots() -> [].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -36,6 +36,9 @@

%%=====================================================================
%% Hocon schema

namespace() -> rocketmq.

roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

Expand Down
Original file line number Diff line number Diff line change
@@ -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, []},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
%% Hocon config schema exports
-export([
roots/0,
fields/1
fields/1,
namespace/0
]).

%% callbacks for behaviour emqx_resource
Expand Down Expand Up @@ -132,6 +133,8 @@
%% Configuration and default values
%%====================================================================

namespace() -> sqlserver.

roots() ->
[{config, #{type => hoconsc:ref(?MODULE, config)}}].

Expand Down
22 changes: 0 additions & 22 deletions apps/emqx_conf/src/emqx_conf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ dump_schema(Dir, SchemaModule) ->
ok = emqx_dashboard_desc_cache:init(),
lists:foreach(
fun(Lang) ->
ok = gen_config_md(Dir, SchemaModule, Lang),
ok = gen_schema_json(Dir, SchemaModule, Lang)
end,
["en", "zh"]
Expand Down Expand Up @@ -468,14 +467,6 @@ bridge_schema_json() ->
SchemaInfo = #{title => <<"EMQX Data Bridge API Schema">>, version => Version},
gen_api_schema_json_iodata(emqx_bridge_api, SchemaInfo).

%% TODO: remove it and also remove hocon_md.erl and friends.
%% markdown generation from schema is a failure and we are moving to an interactive
%% viewer like swagger UI.
gen_config_md(Dir, SchemaModule, Lang) ->
SchemaMdFile = filename:join([Dir, "config-" ++ Lang ++ ".md"]),
io:format(user, "===< Generating: ~s~n", [SchemaMdFile]),
ok = gen_doc(SchemaMdFile, SchemaModule, Lang).

%% @doc return the root schema module.
-spec schema_module() -> module().
schema_module() ->
Expand Down Expand Up @@ -515,19 +506,6 @@ make_desc_resolver(Lang) ->
unicode:characters_to_binary(Desc)
end.

-spec gen_doc(file:name_all(), module(), string()) -> ok.
gen_doc(File, SchemaModule, Lang) ->
Version = emqx_release:version(),
Title =
"# " ++ emqx_release:description() ++ " Configuration\n\n" ++
"<!--" ++ Version ++ "-->",
BodyFile = filename:join([rel, "emqx_conf.template." ++ Lang ++ ".md"]),
{ok, Body} = file:read_file(BodyFile),
Resolver = make_desc_resolver(Lang),
Opts = #{title => Title, body => Body, desc_resolver => Resolver},
Doc = hocon_schema_md:gen(SchemaModule, Opts),
file:write_file(File, Doc).

gen_api_schema_json_iodata(SchemaMod, SchemaInfo) ->
emqx_dashboard_swagger:gen_api_schema_json_iodata(
SchemaMod,
Expand Down
6 changes: 0 additions & 6 deletions apps/emqx_connector/src/emqx_connector_schema_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
password/0
]).

-export([roots/0, fields/1]).

roots() -> [].

fields(_) -> [].

ssl_fields() ->
[
{ssl, #{
Expand Down
6 changes: 4 additions & 2 deletions apps/emqx_connector/src/schema/emqx_connector_ee_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -93,6 +93,8 @@ connector_impl_module(rabbitmq) ->
connector_impl_module(_ConnectorType) ->
undefined.

namespace() -> undefined.

fields(connectors) ->
connector_structs().

Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_dashboard/src/emqx_dashboard_monitor_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
-export([
paths/0,
schema/1,
fields/1
fields/1,
namespace/0
]).

-export([
monitor/2,
monitor_current/2
]).

namespace() -> undefined.

api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true, translate_body => true}).

Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_dashboard/test/emqx_swagger_parameter_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -563,6 +563,7 @@ schema("/method/error") ->
#{operationId => test, bar => #{200 => <<"ok">>}}.

namespace() -> undefined.
roots() -> [].

fields(page) ->
[
Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_dashboard/test/emqx_swagger_remote_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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") ->
[
Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
1 change: 1 addition & 0 deletions apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ to_schema(Object) ->
post => #{responses => #{200 => Object, 201 => Object}}
}.

rotos() -> [].
namespace() -> undefined.

fields(good_ref) ->
Expand Down
5 changes: 4 additions & 1 deletion apps/emqx_gateway/src/emqx_gateway_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
-export([
api_spec/0,
paths/0,
schema/1
schema/1,
namespace/0
]).

-export([
Expand All @@ -59,6 +60,8 @@
%% minirest behaviour callbacks
%%--------------------------------------------------------------------

namespace() -> undefined.

api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).

Expand Down

0 comments on commit 2b46cba

Please sign in to comment.