From 1ff49c10dadb5954893e3ec45134e9df624ad294 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Thu, 24 Sep 2015 13:21:25 +0300 Subject: [PATCH] MT#14477 Documentation enchancement for asynchronous API collections Change-Id: Iec515efd05b47ea0e35594be445f7d55f9e70dfb --- lib/NGCP/Panel/Controller/API/Faxes.pm | 7 +++++++ lib/NGCP/Panel/Controller/API/Root.pm | 1 + share/templates/api/root/collection.tt | 8 +++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/Faxes.pm b/lib/NGCP/Panel/Controller/API/Faxes.pm index 5eda22b6b6..a4f237d213 100644 --- a/lib/NGCP/Panel/Controller/API/Faxes.pm +++ b/lib/NGCP/Panel/Controller/API/Faxes.pm @@ -23,6 +23,13 @@ class_has 'api_description' => ( default => 'Defines the meta information like duration, sender etc for fax recordings. The actual recordings can be fetched via the FaxRecordings relation. NOTE: There is no Location header in the POST method response, as creation is asynchronous.', ); +class_has 'properties' => ( + is => 'ro', + isa => 'HashRef', + default => sub { { + asynchronous => 1, + }; }, +); class_has 'query_params' => ( is => 'ro', diff --git a/lib/NGCP/Panel/Controller/API/Root.pm b/lib/NGCP/Panel/Controller/API/Root.pm index c53ddb9ec2..4d6cd6f659 100644 --- a/lib/NGCP/Panel/Controller/API/Root.pm +++ b/lib/NGCP/Panel/Controller/API/Root.pm @@ -160,6 +160,7 @@ sub GET : Allow { item_actions => $item_actions, sorting_cols => $sorting_cols, uri => $uri, + properties => ( $full_mod->can('properties') ? $full_mod->properties : {} ),# sample => $full_mod->can('documentation_sample') # generate pretty json, but without outer brackets (this is tricky though) ? to_json($full_mod->documentation_sample, {pretty => 1}) =~ s/(^\s*{\s*)|(\s*}\s*$)//rg =~ s/\n /\n/rg : undef, diff --git a/share/templates/api/root/collection.tt b/share/templates/api/root/collection.tt index 80d39db05d..b8f2768914 100644 --- a/share/templates/api/root/collection.tt +++ b/share/templates/api/root/collection.tt @@ -242,10 +242,12 @@ Content-Type: application/json { ' _ props _ '}'; - response = -'HTTP/1.1 201 Created -Location: /api/' _ id _ '/2'; + response = 'HTTP/1.1 201 Created'; + IF !col.properties.asynchronous ; + response = response _ ' +Location: /api/' _ id _ '/2' ; + END ; INCLUDE helpers/api_req_res.tt request=request response=response level=level+3; %]