TT#44116 make swaggerui default and enable destruction protection

the "Try it out" button is disabled for the operations:
    PUT, PATCH, DELETE, POST
and therefore only enabled for GET unless the special request param is used.

Change-Id: Iee8338c18e3e8053d6349a20315a7ef3c2f203d5
changes/80/23580/3
Gerhard Jungwirth 7 years ago
parent 41fa667878
commit bfafe384c1

@ -54,7 +54,18 @@ sub auto :Private {
sub GET : Allow { sub GET : Allow {
my ($self, $c) = @_; my ($self, $c) = @_;
if ($c->req->params->{swaggerui}) { my $response_type;
if ($c->req->params->{swagger}) {
$response_type = 'swagger';
} elsif ($c->req->header('Accept') && $c->req->header('Accept') eq 'application/json') {
$response_type = 'plain_json';
} elsif ($c->req->params->{oldapidoc}) {
$response_type = 'oldapidoc';
} else {
$response_type = 'swaggerui';
}
if ($response_type eq 'swaggerui') {
$c->detach('swaggerui'); $c->detach('swaggerui');
} }
@ -224,7 +235,7 @@ sub GET : Allow {
$c->stash(is_admin_api => 1); $c->stash(is_admin_api => 1);
} }
if($c->req->header('Accept') && $c->req->header('Accept') eq 'application/json') { if ($response_type eq 'plain_json') {
my $body = {}; my $body = {};
foreach my $rel(sort keys %{ $c->stash->{collections} }) { foreach my $rel(sort keys %{ $c->stash->{collections} }) {
my $r = $c->stash->{collections}->{$rel}; my $r = $c->stash->{collections}->{$rel};
@ -242,9 +253,9 @@ sub GET : Allow {
Content_Language => 'en', Content_Language => 'en',
Content_Type => 'application/json', Content_Type => 'application/json',
)); ));
} elsif ($c->req->params->{swagger}) { } elsif ($response_type eq 'swagger') {
$c->detach('swagger'); $c->detach('swagger');
} else { } elsif ($response_type eq 'oldapidoc') {
$c->stash(template => 'api/root.tt'); $c->stash(template => 'api/root.tt');
$c->forward($c->view); $c->forward($c->view);
$c->response->headers(HTTP::Headers->new( $c->response->headers(HTTP::Headers->new(
@ -252,6 +263,8 @@ sub GET : Allow {
Content_Type => 'application/xhtml+xml', Content_Type => 'application/xhtml+xml',
#$self->collections_link_headers, #$self->collections_link_headers,
)); ));
} else {
die 'This should never happen.';
} }
return; return;

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<title>Sipwise NGCP HTTP API documentation</title> <title>Sipwise NGCP HTTP API documentation (version 1)</title>
<link rel="stylesheet" href="/css/ui-lightness/jquery-ui-1.10.3.custom.min.css"></link> <link rel="stylesheet" href="/css/ui-lightness/jquery-ui-1.10.3.custom.min.css"></link>
<link rel="stylesheet" href="/css/font-opensans.css"></link> <link rel="stylesheet" href="/css/font-opensans.css"></link>
<link rel="stylesheet" href="/css/font-awesome.css"></link> <link rel="stylesheet" href="/css/font-awesome.css"></link>
@ -59,8 +59,9 @@
END; END;
chapters.push({ level = 2, id = 'definitions', title = 'Definitions' }); chapters.push({ level = 2, id = 'definitions', title = 'Definitions' });
-%] -%]
<h1>Sipwise NGCP HTTP API Documentation</h1> <h1>Sipwise NGCP HTTP API Documentation (version 1)</h1>
<div class="content"> <div class="content">
See the <a href="/api/">new API documentation (version 2; Swagger) here</a>.
<div class="chapter"> <div class="chapter">
<h2 class="nocount">Table of Contents</h2> <h2 class="nocount">Table of Contents</h2>
<nav> <nav>

@ -1,15 +1,25 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<title>Sipwise NGCP HTTP API documentation (with SwaggerUI)</title> <title>Sipwise NGCP HTTP API documentation (version 2)</title>
<!-- link rel="stylesheet" href="/static/css/bootstrap/bootstrap.css"></link -->
<!-- link rel="stylesheet" href="/static/css/bootstrap/bootstrap-responsive.css"></link -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
<link rel="stylesheet" href="/static/css/sipwise-apidoc.css"> <link rel="stylesheet" href="/static/css/sipwise-apidoc.css">
<link rel="stylesheet" type="text/css" href="/static/js/swaggerui/swagger-ui.css" > <link rel="stylesheet" type="text/css" href="/static/js/swaggerui/swagger-ui.css" >
<!-- link rel="stylesheet" type="text/css" href="/static/js/swaggerui/swagger-own.css" -->
</head> </head>
<body> <body>
[% UNLESS c.req.params.iamverysureallowdestructive %]
<style>
/* disable the try it out buttons */
.opblock-post button.btn.try-out__btn,
.opblock-put button.btn.try-out__btn,
.opblock-patch button.btn.try-out__btn,
.opblock-delete button.btn.try-out__btn {
display: none;
}
</style>
[% END %]
[% [%
chapters = [ chapters = [
{ level = 2, id = 'intro', title = 'Introduction', }, { level = 2, id = 'intro', title = 'Introduction', },
@ -18,25 +28,28 @@
]; ];
-%] -%]
<h1>Sipwise NGCP HTTP API Documentation (with SwaggerUI)</h1> <h1>Sipwise NGCP HTTP API Documentation (version 2)</h1>
<div class="content"> <div class="content">
<div class ="sipwclass">
See the <a href="/api/?oldapidoc=1">old API documentation (version 1) here</a>.
</div>
<div class="chapter sipwclass"> <div class="chapter sipwclass">
<h2 class="nocount">Table of Contents</h2> <h2 class="nocount">Table of Contents</h2>
<nav> <nav>
<ol>
[% FOR chapter IN chapters %]
[% IF loop.prev && loop.prev.level > chapter.level -%]
</ol></li>
[% END -%]
<li><a href="#[% chapter.id %]">[% chapter.title %]</a>
[% IF loop.next && loop.next.level > chapter.level -%]
<ol> <ol>
[% ELSE -%] [% FOR chapter IN chapters %]
</li> [% IF loop.prev && loop.prev.level > chapter.level -%]
</ol></li>
[% END -%]
<li><a href="#[% chapter.id %]">[% chapter.title %]</a>
[% IF loop.next && loop.next.level > chapter.level -%]
<ol>
[% ELSE -%]
</li>
[% END -%]
[% END -%] [% END -%]
[% END -%] </ol>
</ol> </nav>
</nav>
</div> </div>
[% FOR chapter IN chapters -%] [% FOR chapter IN chapters -%]

Loading…
Cancel
Save