diff --git a/lib/NGCP/Panel/Controller/API/Root.pm b/lib/NGCP/Panel/Controller/API/Root.pm
index 610ff05d77..ff8df42a48 100644
--- a/lib/NGCP/Panel/Controller/API/Root.pm
+++ b/lib/NGCP/Panel/Controller/API/Root.pm
@@ -156,6 +156,25 @@ sub GET : Allow {
$sorting_cols = [$item_rs->result_source->columns];
}
my ($form_fields,$form_fields_upload) = $form ? $self->get_collection_properties($form) : ([],[]);
+
+ my $documentation_sample = {} ;
+ my $documentation_sample_process = sub{
+ my $s = shift;
+ $s = to_json($s, {pretty => 1}) =~ s/(^\s*{\s*)|(\s*}\s*$)//rg =~ s/\n /\n/rg;
+ return $s;
+ };
+ if($full_mod->can('documentation_sample')){
+ $documentation_sample->{sample_orig}->{default} = $full_mod->documentation_sample;
+ $documentation_sample->{sample}->{default} = $documentation_sample_process->($documentation_sample->{sample_orig}->{default});
+ }
+ foreach my $action (qw/create update/){
+ my $method = 'documentation_sample_'.$action;
+ if($full_mod->can($method)){
+ $documentation_sample->{sample_orig}->{$action} = $full_mod->$method;
+ $documentation_sample->{sample}->{$action} = $documentation_sample_process->($documentation_sample->{sample_orig}->{$action});
+ }
+ }
+
$c->stash->{collections}->{$rel} = {
name => $mod,
description => $full_mod->api_description,
@@ -168,9 +187,7 @@ sub GET : Allow {
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,
+ %$documentation_sample,
journal_resource_config => $journal_resource_config,
};
diff --git a/lib/NGCP/Panel/Controller/API/Subscribers.pm b/lib/NGCP/Panel/Controller/API/Subscribers.pm
index 75453fbf34..639103fd68 100644
--- a/lib/NGCP/Panel/Controller/API/Subscribers.pm
+++ b/lib/NGCP/Panel/Controller/API/Subscribers.pm
@@ -29,6 +29,12 @@ sub api_description {
'XMPP and place and receive calls via SIP. A subscriber always belongs to a '.
'Customer and is placed inside a Domain.';
}
+sub documentation_sample_update {
+ return { "domain_id" => 4,
+ "password" => "test",
+ "username" => "test",
+ };
+}
sub query_params {
return [
diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm
index 0d9e363724..453c3bdbe1 100644
--- a/lib/NGCP/Panel/Role/API/Subscribers.pm
+++ b/lib/NGCP/Panel/Role/API/Subscribers.pm
@@ -504,6 +504,10 @@ sub update_item {
return;
}
+ if($resource->{customer_id} && ( $resource->{customer_id} != $subscriber->contract->id ) ){
+ $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "customer_id can't be changed.");
+ return;
+ }
if($subscriber->status ne $resource->{status}) {
if($resource->{status} eq 'locked') {
diff --git a/share/templates/api/root/collection.tt b/share/templates/api/root/collection.tt
index 5433f3990b..a47ab23eb9 100644
--- a/share/templates/api/root/collection.tt
+++ b/share/templates/api/root/collection.tt
@@ -12,34 +12,41 @@
[% col.description %]
-[%-
- #props_plain = '"id" : 1';
- props_creation_first_flag = 1;
- FOREACH p IN col.fields;
- NEXT IF p.types.0 == 'null';
- NEXT IF p.type_original == 'Upload';
- IF props_creation_first_flag;
- props_creation_first_flag = 0;
+[% MACRO get_props_plain BLOCK ;
+ IF col.sample.default || (action && col.sample.${action});
+ IF col.sample.default && (!action || !col.sample.${action});
+ props_plain = col.sample.default _ "\n";
ELSE;
- props_plain = props_plain _ ",\n";
+ props_plain = col.sample.${action} _ "\n";
END;
- IF p.types.0 == "Number";
- val = 4;
- ELSIF p.types.0 == "String";
- val = '"test"';
- ELSIF p.types.0 == "Boolean";
- val = 'true';
- ELSIF p.types.0 == "Array";
- val = '[]';
- ELSE;
- val = '"missing"';
+ ELSE;
+ #props_plain = '"id" : 1';
+ props_creation_first_flag = 1;
+ FOREACH p IN col.fields;
+ NEXT IF p.types.0 == 'null';
+ NEXT IF p.type_original == 'Upload';
+ IF props_creation_first_flag;
+ props_creation_first_flag = 0;
+ ELSE;
+ props_plain = props_plain _ ",\n";
+ END;
+ IF p.types.0 == "Number";
+ val = 4;
+ ELSIF p.types.0 == "String";
+ val = '"test"';
+ ELSIF p.types.0 == "Boolean";
+ val = 'true';
+ ELSIF p.types.0 == "Array";
+ val = '[]';
+ ELSE;
+ val = '"missing"';
+ END;
+ props_plain = props_plain _ '"' _ p.name _ '" : ' _ val;
END;
- props_plain = props_plain _ '"' _ p.name _ '" : ' _ val;
- END;
- props_plain = props_plain _ "\n";
- IF col.sample;
- props_plain = col.sample _ "\n";
+ props_plain = props_plain _ "\n";
END;
+ props_plain;
+END;
%]
[%-
FOREACH p IN col.uploads;
@@ -129,7 +136,7 @@ Accept-Post: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/#re
cmd = 'curl -i -X GET -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/?page=1&rows=1\'';
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
- props = props_plain | indent(12);
+ props = get_props_plain() | indent(12);
request =
'GET /api/' _ id _ '/?page=1&rows=1 HTTP/1.1';
@@ -197,7 +204,7 @@ Content-Type: application/hal+json; profile="http://purl.org/sipwise/ngcp-api/"
cmd = 'curl -i -X GET -H \'Connection: close\' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/1\'';
INCLUDE helpers/api_command.tt cmd=cmd level=level+3;
- props = props_plain | indent(3);
+ props = get_props_plain() | indent(3);
request =
'GET /api/' _ id _ '/1 HTTP/1.1';
@@ -233,38 +240,42 @@ Link: ; rel="item self"
[% END -%]
[% MACRO request_macro BLOCK ;
- props = props_plain | collapse;
+ IF http_request == 'POST' ;
+ action = 'create';
+ response = 'HTTP/1.1 201 Created';
+ IF !col.properties.asynchronous ;
+ response = response _ '
+Location: /api/' _ id _ '/2' ;
+ END ;
+ ELSIF http_request == 'PUT' ;
+ action = 'update';
+ item_id = 2;
+ request_headers = "\nPrefer: return=minimal";
+ request_headers_form = ' -H \'Prefer: return=minimal\'';
+ response =
+'HTTP/1.1 204 No Content
+Preference-Applied: return=minimal';
+ END;
+
+ props = get_props_plain( action => action) | collapse;
uploads_form = uploads_form | collapse;
content_type = col.config.action.${http_request}.ContentType.0 ? col.config.action.${http_request}.ContentType.0 : 'application/json';
+
IF content_type == 'multipart/form-data' ;
request_data_plain = '\'json={' _ props _ '}\' ';
- props = props_plain | indent(6);
+ props = get_props_plain( action => action) | indent(6);
uploads_data = uploads_data | indent(3);
request_data = "{\n json => {\n" _ props _ ( uploads_data ? " }\n" _ uploads_data : "" ) _ "\n}";
request_form = ' --form ' _ request_data_plain _ uploads_form ;
ELSE;
request_data_plain = '\'{' _ props _ '}\'';
- props = props_plain | indent(3);
+ props = get_props_plain( action => action) | indent(3);
uploads_data = uploads_data | indent(0);
request_data = "{\n" _ props _ ( uploads_data ? "\n" _ uploads_data : "" ) _ "}";
request_form = ' --data-binary ' _ request_data_plain _ uploads_form;
END;
- IF http_request == 'POST' ;
- response = 'HTTP/1.1 201 Created';
- IF !col.properties.asynchronous ;
- response = response _ '
-Location: /api/' _ id _ '/2' ;
- END ;
- ELSIF http_request == 'PUT' ;
- item_id = 2;
- request_headers = "\nPrefer: return=minimal";
- request_headers_form = ' -H \'Prefer: return=minimal\'';
- response =
-'HTTP/1.1 204 No Content
-Preference-Applied: return=minimal';
- END;
cmd = 'curl -i -X ' _ http_request _ ' -H \'Connection: close\' -H \'Content-Type: ' _ content_type _ '\'' _ request_headers_form _ ' --cert NGCP-API-client-certificate.pem --cacert ca-cert.pem \'https://example.org:1443/api/' _ id _ '/' _ item_id _ '\' ' _ request_form ;
@@ -303,6 +314,7 @@ END%]
[%
props = ''; rem = 0; rep = 0;
FOREACH p IN col.fields;
+ NEXT IF col.sample_orig && col.sample_orig.update && ( col.sample_orig.update != 'default' ) && ( !col.sample_orig.update.${p.name} );
type = p.types.0;
IF type == 'null';
NEXT IF rem >= 1;
@@ -365,6 +377,7 @@ END%]
[%
props = ''; rem = 0; rep = 0;
FOREACH p IN col.fields;
+ NEXT IF col.sample_orig && col.sample_orig.update && ( !col.sample_orig.update.${p.name} );
type = p.types.0;
IF type == 'null';
NEXT IF rem >= 1;