feat(api): provide utility to qualify API URIs
This commit is contained in:
parent
64f15f1fdb
commit
54e54cc63d
|
@ -41,8 +41,6 @@
|
||||||
-include_lib("emqx/include/http_api.hrl").
|
-include_lib("emqx/include/http_api.hrl").
|
||||||
-include_lib("emqx/include/emqx_release.hrl").
|
-include_lib("emqx/include/emqx_release.hrl").
|
||||||
|
|
||||||
-define(BASE_PATH, "/api/v5").
|
|
||||||
|
|
||||||
-define(EMQX_MIDDLE, emqx_dashboard_middleware).
|
-define(EMQX_MIDDLE, emqx_dashboard_middleware).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -61,7 +59,7 @@ start_listeners(Listeners) ->
|
||||||
GlobalSpec = #{
|
GlobalSpec = #{
|
||||||
openapi => "3.0.0",
|
openapi => "3.0.0",
|
||||||
info => #{title => "EMQX API", version => ?EMQX_API_VERSION},
|
info => #{title => "EMQX API", version => ?EMQX_API_VERSION},
|
||||||
servers => [#{url => ?BASE_PATH}],
|
servers => [#{url => emqx_dashboard_swagger:base_path()}],
|
||||||
components => #{
|
components => #{
|
||||||
schemas => #{},
|
schemas => #{},
|
||||||
'securitySchemes' => #{
|
'securitySchemes' => #{
|
||||||
|
@ -78,11 +76,11 @@ start_listeners(Listeners) ->
|
||||||
{"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}},
|
{"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}},
|
||||||
{"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}},
|
{"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}},
|
||||||
{emqx_mgmt_api_status:path(), emqx_mgmt_api_status, []},
|
{emqx_mgmt_api_status:path(), emqx_mgmt_api_status, []},
|
||||||
{?BASE_PATH ++ "/[...]", emqx_dashboard_bad_api, []},
|
{emqx_dashboard_swagger:relative_uri("/[...]"), emqx_dashboard_bad_api, []},
|
||||||
{'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}}
|
{'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}}
|
||||||
],
|
],
|
||||||
BaseMinirest = #{
|
BaseMinirest = #{
|
||||||
base_path => ?BASE_PATH,
|
base_path => emqx_dashboard_swagger:base_path(),
|
||||||
modules => minirest_api:find_api_modules(apps()),
|
modules => minirest_api:find_api_modules(apps()),
|
||||||
authorization => Authorization,
|
authorization => Authorization,
|
||||||
security => [#{'basicAuth' => []}, #{'bearerAuth' => []}],
|
security => [#{'basicAuth' => []}, #{'bearerAuth' => []}],
|
||||||
|
|
|
@ -19,12 +19,16 @@
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("hocon/include/hoconsc.hrl").
|
-include_lib("hocon/include/hoconsc.hrl").
|
||||||
|
|
||||||
|
-define(BASE_PATH, "/api/v5").
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([spec/1, spec/2]).
|
-export([spec/1, spec/2]).
|
||||||
-export([namespace/0, namespace/1, fields/1]).
|
-export([namespace/0, namespace/1, fields/1]).
|
||||||
-export([schema_with_example/2, schema_with_examples/2]).
|
-export([schema_with_example/2, schema_with_examples/2]).
|
||||||
-export([error_codes/1, error_codes/2]).
|
-export([error_codes/1, error_codes/2]).
|
||||||
-export([file_schema/1]).
|
-export([file_schema/1]).
|
||||||
|
-export([base_path/0]).
|
||||||
|
-export([relative_uri/1]).
|
||||||
|
|
||||||
-export([filter_check_request/2, filter_check_request_and_translate_body/2]).
|
-export([filter_check_request/2, filter_check_request_and_translate_body/2]).
|
||||||
|
|
||||||
|
@ -177,6 +181,14 @@ error_codes(Codes = [_ | _], MsgDesc) ->
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
-spec base_path() -> uri_string:uri_string().
|
||||||
|
base_path() ->
|
||||||
|
?BASE_PATH.
|
||||||
|
|
||||||
|
-spec relative_uri(uri_string:uri_string()) -> uri_string:uri_string().
|
||||||
|
relative_uri(Uri) ->
|
||||||
|
base_path() ++ Uri.
|
||||||
|
|
||||||
file_schema(FileName) ->
|
file_schema(FileName) ->
|
||||||
#{
|
#{
|
||||||
content => #{
|
content => #{
|
||||||
|
|
Loading…
Reference in New Issue