emqx_swagger_remote_schema.erl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_swagger_remote_schema).
  17. -include_lib("typerefl/include/types.hrl").
  18. -export([namespace/0, roots/0, fields/1]).
  19. -import(hoconsc, [mk/2]).
  20. roots() -> ["root"].
  21. namespace() -> undefined.
  22. fields("root") ->
  23. [
  24. {listeners,
  25. hoconsc:array(
  26. hoconsc:union([
  27. hoconsc:ref(?MODULE, "ref1"),
  28. hoconsc:ref(?MODULE, "ref2")
  29. ])
  30. )},
  31. {default_username, fun default_username/1},
  32. {default_password, fun default_password/1},
  33. {sample_interval, mk(emqx_schema:timeout_duration_s(), #{default => <<"10s">>})},
  34. {token_expired_time, mk(emqx_schema:duration(), #{default => <<"30m">>})}
  35. ];
  36. fields("ref1") ->
  37. [
  38. {"protocol", hoconsc:enum([http, https])},
  39. {"port", mk(integer(), #{default => 18083})}
  40. ];
  41. fields("ref2") ->
  42. [
  43. {page, mk(range(1, 100), #{desc => <<"good page">>})},
  44. {another_ref, hoconsc:ref(?MODULE, "ref3")}
  45. ];
  46. fields("ref3") ->
  47. [
  48. {ip, mk(emqx_schema:ip_port(), #{desc => <<"IP:Port">>, example => "127.0.0.1:80"})},
  49. {version, mk(string(), #{desc => "a good version", example => "1.0.0"})}
  50. ].
  51. default_username(type) -> string();
  52. default_username(default) -> <<"admin">>;
  53. default_username(required) -> true;
  54. default_username(_) -> undefined.
  55. default_password(type) -> string();
  56. default_password(default) -> "public";
  57. default_password(required) -> true;
  58. default_password(_) -> undefined.