From af07986eecc21faffe6d9e24f634b4108129bbd1 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 23 Nov 2012 22:49:11 +0100 Subject: [PATCH] New design for self documented router. The documentation is built only on demand. A mapping entry can be hidden for the documentation One can change the status code when building itself the WSF_ROUTER_SELF_DOCUMENTATION_MESSAGE --- .../wsf_router_mapping_documentation.e | 52 ++++++ .../wsf_router_self_documentation_message.e | 155 ++++++++++-------- .../wsf_self_documented_handler.e | 2 +- .../wsf_self_documented_router_mapping.e | 12 +- .../starts_with/wsf_starts_with_mapping.e | 2 +- .../wsf/router/support/uri/wsf_uri_mapping.e | 2 +- .../uri_template/wsf_uri_template_mapping.e | 2 +- .../wsf_uri_template_context_mapping.e | 2 +- .../server/wsf/router/wsf_router_mapping.e | 8 + 9 files changed, 163 insertions(+), 74 deletions(-) create mode 100644 library/server/wsf/router/documentation/wsf_router_mapping_documentation.e diff --git a/library/server/wsf/router/documentation/wsf_router_mapping_documentation.e b/library/server/wsf/router/documentation/wsf_router_mapping_documentation.e new file mode 100644 index 00000000..ea334357 --- /dev/null +++ b/library/server/wsf/router/documentation/wsf_router_mapping_documentation.e @@ -0,0 +1,52 @@ +note + description: "Summary description for {WSF_ROUTER_MAPPING_DOCUMENTATION}." + date: "$Date$" + revision: "$Revision$" + +class + WSF_ROUTER_MAPPING_DOCUMENTATION + +create + make + +feature {NONE} -- Initialization + + make (m: like mapping) + do + mapping := m + create {STRING_32} description.make_empty + end + +feature -- Status report + + is_hidden: BOOLEAN + -- Hide this mapping from any self documentation? + -- Default=False + + is_empty: BOOLEAN + -- Is Current empty? + -- i.e: does not carry any information. + do + Result := description.is_empty + end + +feature -- Access + + mapping: WSF_ROUTER_MAPPING + -- Associated mapping + + description: STRING_32 + +feature -- Change + + set_is_hidden (b: BOOLEAN) + do + is_hidden := b + end + + add_description (d: READABLE_STRING_GENERAL) + do + description.append_string_general (d) + end + +end diff --git a/library/server/wsf/router/documentation/wsf_router_self_documentation_message.e b/library/server/wsf/router/documentation/wsf_router_self_documentation_message.e index cc2e5d7f..051446a9 100644 --- a/library/server/wsf/router/documentation/wsf_router_self_documentation_message.e +++ b/library/server/wsf/router/documentation/wsf_router_self_documentation_message.e @@ -21,6 +21,7 @@ feature {NONE} -- Initialization make (req: WSF_REQUEST; a_router: WSF_ROUTER) -- Make Current for request `req' and router `a_router' do + status_code := {HTTP_STATUS_CODE}.ok request := req router := a_router end @@ -31,13 +32,21 @@ feature {NONE} -- Initialization --| note: it could be "/doc" or "/api/doc" or ... do make (req, a_router) - if a_resource /= Void and then attached a_router.base_url as l_base_url then - resource := l_base_url + a_resource + if a_resource /= Void then + if attached a_router.base_url as l_base_url then + resource := l_base_url + a_resource + else + resource := a_resource + end end end feature -- Access + status_code: INTEGER + -- Associated status code + -- Default is Ok + request: WSF_REQUEST router: WSF_ROUTER @@ -57,6 +66,13 @@ feature -- Properties feature -- Change + set_status_code (c: like status_code) + require + c_positive_or_zero: c >= 0 + do + status_code := c + end + set_header (v: like header) do header := v @@ -97,8 +113,10 @@ feature {WSF_RESPONSE} -- Output l_description.append ("[ ]") @@ -141,12 +159,12 @@ feature {WSF_RESPONSE} -- Output l_description.append ("Index
") end if attached router.item_associated_with_resource (l_api_resource, Void) as l_api_item then - l_description.append ("

Information related to %"" + l_api_resource + "%"