From 4eb27ce25bf4ec6622552a87ee2babd15f6e069b Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 22 Nov 2021 14:37:44 +0800 Subject: [PATCH] fix(gw): fix bad paging params --- .../src/emqx_gateway_api_authn.erl | 18 +++++++++++++---- .../src/emqx_gateway_api_listeners.erl | 20 +++++++++++++------ apps/emqx_gateway/src/emqx_gateway_http.erl | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/emqx_gateway/src/emqx_gateway_api_authn.erl b/apps/emqx_gateway/src/emqx_gateway_api_authn.erl index f5b6b3dff..cd6c46b29 100644 --- a/apps/emqx_gateway/src/emqx_gateway_api_authn.erl +++ b/apps/emqx_gateway/src/emqx_gateway_api_authn.erl @@ -82,6 +82,7 @@ authn(get, #{bindings := #{name := Name0}}) -> authn(put, #{bindings := #{name := Name0}, body := Body}) -> with_gateway(Name0, fun(GwName, _) -> + %% TODO: return the authn instances? ok = emqx_gateway_http:update_authn(GwName, Body), {204} end); @@ -89,6 +90,7 @@ authn(put, #{bindings := #{name := Name0}, authn(post, #{bindings := #{name := Name0}, body := Body}) -> with_gateway(Name0, fun(GwName, _) -> + %% TODO: return the authn instances? ok = emqx_gateway_http:add_authn(GwName, Body), {204} end); @@ -210,7 +212,8 @@ schema("/gateway/:name/authentication/users") -> #{ 'operationId' => users , get => #{ description => <<"Get the users for the authentication">> - , parameters => params_gateway_name_in_path() + , parameters => params_gateway_name_in_path() ++ + params_paging_in_qs() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -224,6 +227,9 @@ schema("/gateway/:name/authentication/users") -> post => #{ description => <<"Add user for the authentication">> , parameters => params_gateway_name_in_path() + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( + ref(emqx_authn_api, request_user_create), + emqx_authn_api:request_user_create_examples()) , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -257,6 +263,9 @@ schema("/gateway/:name/authentication/users/:uid") -> "authentication">> , parameters => params_gateway_name_in_path() ++ params_userid_in_path() + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( + ref(emqx_authn_api, request_user_update), + emqx_authn_api:request_user_update_examples()) , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -271,8 +280,7 @@ schema("/gateway/:name/authentication/users/:uid") -> #{ description => <<"Delete the user for the gateway " "authentication">> , parameters => params_gateway_name_in_path() ++ - params_userid_in_path() ++ - params_paging_in_qs() + params_userid_in_path() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -325,10 +333,12 @@ params_userid_in_path() -> params_paging_in_qs() -> [{page, mk(integer(), #{ in => query - , desc => <<"Page Number">> + , nullable => true + , desc => <<"Page Index">> })}, {limit, mk(integer(), #{ in => query + , nullable => true , desc => <<"Page Limit">> })} ]. diff --git a/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl b/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl index 62b871fa0..f1744363c 100644 --- a/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl +++ b/apps/emqx_gateway/src/emqx_gateway_api_listeners.erl @@ -353,7 +353,8 @@ schema("/gateway/:name/listeners/:id/authentication/users") -> , get => #{ description => <<"Get the users for the authentication">> , parameters => params_gateway_name_in_path() ++ - params_listener_id_in_path() + params_listener_id_in_path() ++ + params_paging_in_qs() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -368,6 +369,9 @@ schema("/gateway/:name/listeners/:id/authentication/users") -> #{ description => <<"Add user for the authentication">> , parameters => params_gateway_name_in_path() ++ params_listener_id_in_path() + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( + ref(emqx_authn_api, request_user_create), + emqx_authn_api:request_user_create_examples()) , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -403,6 +407,9 @@ schema("/gateway/:name/listeners/:id/authentication/users/:uid") -> , parameters => params_gateway_name_in_path() ++ params_listener_id_in_path() ++ params_userid_in_path() + , 'requestBody' => emqx_dashboard_swagger:schema_with_examples( + ref(emqx_authn_api, request_user_update), + emqx_authn_api:request_user_update_examples()) , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -418,8 +425,7 @@ schema("/gateway/:name/listeners/:id/authentication/users/:uid") -> "authentication">> , parameters => params_gateway_name_in_path() ++ params_listener_id_in_path() ++ - params_userid_in_path() ++ - params_paging_in_qs() + params_userid_in_path() , responses => #{ 400 => error_codes([?BAD_REQUEST], <<"Bad Request">>) , 404 => error_codes([?NOT_FOUND], <<"Not Found">>) @@ -481,10 +487,12 @@ params_userid_in_path() -> params_paging_in_qs() -> [{page, mk(integer(), #{ in => query - , desc => <<"Page Number">> + , nullable => true + , desc => <<"Page Index">> })}, {limit, mk(integer(), #{ in => query + , nullable => true , desc => <<"Page Limit">> })} ]. @@ -630,7 +638,7 @@ common_listener_opts() -> %% examples examples_listener_list() -> - [examples_listener()]. + #{stomp_listeners => [examples_listener()]}. examples_listener() -> - #{id => true}. + #{}. diff --git a/apps/emqx_gateway/src/emqx_gateway_http.erl b/apps/emqx_gateway/src/emqx_gateway_http.erl index a35a4d504..345335ff3 100644 --- a/apps/emqx_gateway/src/emqx_gateway_http.erl +++ b/apps/emqx_gateway/src/emqx_gateway_http.erl @@ -328,7 +328,7 @@ codestr(500) -> 'UNKNOW_ERROR'. -spec with_authn(binary(), function()) -> any(). with_authn(GwName0, Fun) -> - with_gateway(GwName0, fun(GwName) -> + with_gateway(GwName0, fun(GwName, _GwConf) -> Authn = emqx_gateway_http:authn(GwName), Fun(GwName, Authn) end).