Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): fix swagger spec generation #9997

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/emqx_dashboard/src/emqx_dashboard_swagger.erl
Expand Up @@ -417,13 +417,17 @@ init_prop(Keys, Init, Type) ->
fun(Key, Acc) ->
case hocon_schema:field_schema(Type, Key) of
undefined -> Acc;
Schema -> Acc#{Key => to_bin(Schema)}
Schema -> Acc#{Key => format_prop(Key, Schema)}
savonarola marked this conversation as resolved.
Show resolved Hide resolved
end
end,
Init,
Keys
).

format_prop(deprecated, Value) when is_boolean(Value) -> Value;
format_prop(deprecated, _) -> true;
format_prop(_, Schema) -> to_bin(Schema).

trans_required(Spec, true, _) -> Spec#{required => true};
trans_required(Spec, _, path) -> Spec#{required => true};
trans_required(Spec, _, _) -> Spec.
Expand Down
32 changes: 31 additions & 1 deletion apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl
Expand Up @@ -94,6 +94,30 @@ t_object(_Config) ->
validate("/object", Spec, Refs),
ok.

t_deprecated(_Config) ->
?assertMatch(
[
#{
<<"emqx_swagger_requestBody_SUITE.deprecated_ref">> :=
#{
<<"properties">> :=
[
{<<"tag1">>, #{
deprecated := true
}},
{<<"tag2">>, #{
deprecated := true
}},
{<<"tag3">>, #{
deprecated := false
}}
]
}
}
],
emqx_dashboard_swagger:components([{?MODULE, deprecated_ref}], #{})
).

t_nest_object(_Config) ->
GoodRef = <<"#/components/schemas/emqx_swagger_requestBody_SUITE.good_ref">>,
Spec = #{
Expand Down Expand Up @@ -812,7 +836,13 @@ fields(sub_fields) ->
{init_file, fun init_file/1}
],
desc => <<"test sub fields">>
}.
};
fields(deprecated_ref) ->
[
{tag1, mk(binary(), #{desc => <<"tag1">>, deprecated => {since, "4.3.0"}})},
{tag2, mk(binary(), #{desc => <<"tag2">>, deprecated => true})},
{tag3, mk(binary(), #{desc => <<"tag3">>, deprecated => false})}
].

enable(type) -> boolean();
enable(desc) -> <<"Whether to enable tls psk support">>;
Expand Down
3 changes: 2 additions & 1 deletion apps/emqx_modules/test/emqx_telemetry_SUITE.erl
Expand Up @@ -858,7 +858,8 @@ stop_slave(Node) ->
ok = slave:stop(Node),
?assertEqual([node()], mria_mnesia:running_nodes()),
?assertEqual([], nodes()),
ok.
_ = application:stop(mria),
ok = application:start(mria).

leave_cluster() ->
try mnesia_hook:module_info() of
Expand Down
1 change: 1 addition & 0 deletions changes/ce/fix-9997.en.md
@@ -0,0 +1 @@
Fix Swagger API schema generation. `deprecated` metadata field is now always boolean, as [Swagger specification](https://swagger.io/specification/) suggests.
1 change: 1 addition & 0 deletions changes/ce/fix-9997.zh.md
@@ -0,0 +1 @@
修复 Swagger API 生成时,`deprecated` 元数据字段未按照[标准](https://swagger.io/specification/)建议的那样始终为布尔值的问题。