Merge pull request #6283 from DDDHuang/as_doc_example

fix: add auto subscription swagger example
This commit is contained in:
DDDHuang 2021-12-09 10:35:08 +08:00 committed by GitHub
commit 7aa08a82d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 3 deletions

View File

@ -25,13 +25,39 @@
-define(EXCEED_LIMIT, 'EXCEED_LIMIT').
-define(BAD_REQUEST, 'BAD_REQUEST').
-include_lib("emqx/include/emqx_placeholder.hrl").
api_spec() ->
{[auto_subscribe_api()], []}.
schema() ->
emqx_mgmt_util:schema(
emqx_mgmt_api_configs:gen_schema(
emqx:get_raw_config([auto_subscribe, topics])), <<"">>).
case emqx_mgmt_api_configs:gen_schema(emqx:get_config([auto_subscribe, topics])) of
#{example := <<>>, type := string} ->
emqx_mgmt_util:schema(auto_subscribe_conf_example());
Example ->
emqx_mgmt_util:schema(Example)
end.
auto_subscribe_conf_example() ->
#{
type => array,
items => #{
type => object,
properties =>#{
topic => #{
type => string,
example => <<
"/clientid/", ?PH_S_CLIENTID,
"/username/", ?PH_S_USERNAME,
"/host/", ?PH_S_HOST,
"/port/", ?PH_S_PORT>>},
qos => #{example => 0, type => number, enum => [0, 1, 2]},
rh => #{example => 0, type => number, enum => [0, 1, 2]},
nl => #{example => 0, type => number, enum => [0, 1]},
rap => #{example => 0, type => number, enum => [0, 1]}
}
}
}.
auto_subscribe_api() ->
Metadata = #{