fix: responses/error_code support ?DESC/x.
This commit is contained in:
parent
f5c5e1f96e
commit
c37f01fd3e
|
@ -150,13 +150,12 @@ error_codes(Codes) ->
|
||||||
error_codes(Codes, <<"Error code to troubleshoot problems.">>).
|
error_codes(Codes, <<"Error code to troubleshoot problems.">>).
|
||||||
|
|
||||||
-spec error_codes(nonempty_list(atom()), binary()) -> hocon_schema:fields().
|
-spec error_codes(nonempty_list(atom()), binary()) -> hocon_schema:fields().
|
||||||
error_codes(Codes = [_ | _], MsgExample) ->
|
error_codes(Codes = [_ | _], MsgDesc) ->
|
||||||
[
|
[
|
||||||
{code, hoconsc:mk(hoconsc:enum(Codes))},
|
{code, hoconsc:mk(hoconsc:enum(Codes))},
|
||||||
{message,
|
{message,
|
||||||
hoconsc:mk(string(), #{
|
hoconsc:mk(string(), #{
|
||||||
desc => <<"Details description of the error.">>,
|
desc => MsgDesc
|
||||||
example => MsgExample
|
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -443,6 +442,9 @@ responses(Responses, Module, Options) ->
|
||||||
{Spec, Refs, _, _} = maps:fold(fun response/3, {#{}, [], Module, Options}, Responses),
|
{Spec, Refs, _, _} = maps:fold(fun response/3, {#{}, [], Module, Options}, Responses),
|
||||||
{Spec, Refs}.
|
{Spec, Refs}.
|
||||||
|
|
||||||
|
response(Status, ?DESC(_Mod, _Id) = Schema, {Acc, RefsAcc, Module, Options}) ->
|
||||||
|
Desc = trans_description(#{}, #{desc => Schema}),
|
||||||
|
{Acc#{integer_to_binary(Status) => Desc}, RefsAcc, Module, Options};
|
||||||
response(Status, Bin, {Acc, RefsAcc, Module, Options}) when is_binary(Bin) ->
|
response(Status, Bin, {Acc, RefsAcc, Module, Options}) when is_binary(Bin) ->
|
||||||
{Acc#{integer_to_binary(Status) => #{description => Bin}}, RefsAcc, Module, Options};
|
{Acc#{integer_to_binary(Status) => #{description => Bin}}, RefsAcc, Module, Options};
|
||||||
%% Support swagger raw object(file download).
|
%% Support swagger raw object(file download).
|
||||||
|
|
|
@ -67,16 +67,15 @@ t_error(_Config) ->
|
||||||
<<"properties">> =>
|
<<"properties">> =>
|
||||||
[
|
[
|
||||||
{<<"code">>, #{enum => ['Bad1', 'Bad2'], type => string}},
|
{<<"code">>, #{enum => ['Bad1', 'Bad2'], type => string}},
|
||||||
{<<"message">>, #{description => <<"Details description of the error.">>,
|
{<<"message">>, #{description => <<"Bad request desc">>, type => string}}]
|
||||||
example => <<"Bad request desc">>, type => string}}]
|
|
||||||
}}}},
|
}}}},
|
||||||
Error404 = #{<<"content">> =>
|
Error404 = #{<<"content">> =>
|
||||||
#{<<"application/json">> => #{<<"schema">> => #{<<"type">> => object,
|
#{<<"application/json">> => #{<<"schema">> => #{<<"type">> => object,
|
||||||
<<"properties">> =>
|
<<"properties">> =>
|
||||||
[
|
[
|
||||||
{<<"code">>, #{enum => ['Not-Found'], type => string}},
|
{<<"code">>, #{enum => ['Not-Found'], type => string}},
|
||||||
{<<"message">>, #{description => <<"Details description of the error.">>,
|
{<<"message">>, #{
|
||||||
example => <<"Error code to troubleshoot problems.">>, type => string}}]
|
description => <<"Error code to troubleshoot problems.">>, type => string}}]
|
||||||
}}}},
|
}}}},
|
||||||
{OperationId, Spec, Refs} = emqx_dashboard_swagger:parse_spec_ref(?MODULE, Path, #{}),
|
{OperationId, Spec, Refs} = emqx_dashboard_swagger:parse_spec_ref(?MODULE, Path, #{}),
|
||||||
?assertEqual(test, OperationId),
|
?assertEqual(test, OperationId),
|
||||||
|
|
Loading…
Reference in New Issue