Merge pull request #10207 from sstrigler/EMQX-9286-use-label-from-i-18-n-files-as-summary-for-open-api-spec

feat(emqx_dashboard): use label as summary in OpenAPI spec
This commit is contained in:
Stefan Strigler 2023-03-23 14:58:21 +01:00 committed by GitHub
commit 2803aff798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -457,7 +457,18 @@ trans_description(Spec, Hocon) ->
Spec; Spec;
Desc -> Desc ->
Desc1 = binary:replace(Desc, [<<"\n">>], <<"<br/>">>, [global]), Desc1 = binary:replace(Desc, [<<"\n">>], <<"<br/>">>, [global]),
Spec#{description => Desc1} maybe_add_summary_from_label(Spec#{description => Desc1}, Hocon)
end.
maybe_add_summary_from_label(Spec, Hocon) ->
Label =
case desc_struct(Hocon) of
?DESC(_, _) = Struct -> get_i18n(<<"label">>, Struct, undefined);
_ -> undefined
end,
case Label of
undefined -> Spec;
_ -> Spec#{summary => Label}
end. end.
get_i18n(Key, Struct, Default) -> get_i18n(Key, Struct, Default) ->

View File

@ -0,0 +1 @@
Use 'label' from i18n file as 'summary' in OpenAPI spec.