TT#69423 - Implement yaml support for API swagger

* Add yaml format response when accessing
	   '/api/?swagger=yml'

Change-Id: I2dae15ae8de9424020d11bc9682ef51350e3fdab
(cherry picked from commit a87b41ce23)
changes/59/34859/2
Flaviu Mates 6 years ago
parent 7e35193d48
commit d8e5d8ef25

@ -9,7 +9,8 @@ use HTTP::Headers qw();
use HTTP::Response qw();
use HTTP::Status qw(:constants);
use File::Find::Rule;
use JSON qw(to_json);
use JSON qw(to_json encode_json);
use YAML::XS qw/Dump/;
use Safe::Isa qw($_isa);
use NGCP::Panel::Utils::API;
use parent qw/Catalyst::Controller NGCP::Panel::Role::API/;
@ -292,13 +293,18 @@ sub swagger :Private {
$user_role,
);
use JSON qw/encode_json/;
$c->response->headers(HTTP::Headers->new(
Content_Language => 'en',
Content_Type => 'application/json',
));
$c->response->body(encode_json($result));
my $headers = HTTP::Headers->new(Content_Language => 'en');
my $response;
if ($c->req->params->{swagger} eq 'yml') {
$headers->header(Content_Type => 'application/x-yaml');
$response = Dump($result);
}
else {
$headers->header(Content_Type => 'application/json');
$response = encode_json($result);
}
$c->response->headers($headers);
$c->response->body($response);
$c->response->code(200);
return;
}

Loading…
Cancel
Save