From 2de3e6cfee1c91669d961afde38b1a10ae45ba1c Mon Sep 17 00:00:00 2001 From: Luca Favatella Date: Tue, 7 Mar 2017 23:00:51 +0000 Subject: [PATCH] Highlight the role of the `:id` binding in cowboy route * https://github.com/inaka/sumo_rest/blob/0.3.3/src/sr_state.erl#L42 * Function spec may be further detailed, but that would require type spec and new internal type (for mandatory key); * Having a field and exported function for id is enough. * https://github.com/inaka/sumo_rest/blob/0.3.3/src/sr_single_entity_handler.erl#L43 * It already comments on the :id element of cowboy route clearly. * https://github.com/inaka/sumo_rest/blob/0.3.3/src/sr_request.erl#L18 * Added internal type for documentation purpose. * https://github.com/inaka/sumo_db/blob/0.7.1/src/sumo_internal.erl#L88 * See https://github.com/inaka/sumo_db/pull/294 * https://github.com/inaka/sumo_rest/blob/0.3.3/test/sr_test/sr_single_session_handler.erl#L60 and https://github.com/inaka/sumo_rest/blob/0.3.3/test/sr_test/sr_single_element_handler.erl#L66 * They already mention `:id` clearly; * The only source of confusion may be whether the name of the parameter in the Swagger schema e.g. [this](https://github.com/inaka/sumo_rest/blob/0.3.3/test/sr_test/sr_single_element_handler.erl#L33) needed to be called `id` e.g. in case cowboy_swagger enforces it. * https://github.com/inaka/sumo_rest/blob/0.3.3/README.md * It already mentions `:id` clearly. --- src/sr_request.erl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sr_request.erl b/src/sr_request.erl index 9be4f4c..a0acad8 100644 --- a/src/sr_request.erl +++ b/src/sr_request.erl @@ -11,11 +11,13 @@ %%% Types %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-type binding_name() :: id | atom(). + -opaque req() :: #{ body := sr_json:json() , headers := [{binary(), iodata()}] , path := binary() - , bindings := #{atom() => any()} + , bindings := #{binding_name() => any()} }. -export_type [req/0].