<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body link="#0B6CDA" vlink="#551A8B" text="#000000" alink="#EE0000">
Hi All<br>
<br>
I am trying to write a Dancer2 Plugin to handle OpenAPI (Swagger2)
configs and I want to configure the plugin via config as usual.<br>
In my config.yml, I have :-<br>
<br>
<font color="#000099">plugins:<br>
OpenAPI:<br>
configfile: "openapicfg.yml"</font><br>
<br>
my Dancer2::Plugin::OpenAPI.pm looks like this:-<br>
<br>
<font color="#000099">package Dancer2::Plugin::OpenAPI;<br>
<br>
use Dancer2::Plugin;<br>
use Dancer2::Plugin::OpenAPI::Core;<br>
use Data::Dumper;<br>
<br>
register OpenAPI => sub {<br>
my $self = shift;<br>
my $plugin_conf = plugin_setting();<br>
print Dumper { pluginconf => $plugin_conf };<br>
<br>
.........<br>
};<br>
</font><br>
and Dancer2::Plugin::OpenAPI::Core has :-<br>
<br>
<font color="#000099">package Dancer2::Plugin::OpenAPI::Core;<br>
<br>
use Moo;<br>
use JSON::Validator::OpenAPI;<br>
use Data::Dumper;<br>
<br>
has 'apiconfig' => (<br>
is => 'rw',<br>
reader => 'get_apiconfig',<br>
writer => 'set_apiconfig'<br>
);<br>
<br>
sub BUILD {<br>
my $self = shift;<br>
my $config = shift;<br>
my $val = JSON::Validator::OpenAPI->new;<br>
my $url = $config->{url};<br>
my $spec = $val->load_and_validate_schema($url);<br>
$self->set_apiconfig($val->schema->data);<br>
return $self;<br>
}<br>
1;</font><br>
<br>
My App has this :-<br>
<br>
<font color="#000099">package MyApi;<br>
use strict;<br>
use warnings;<br>
<br>
use Dancer2;<br>
use Dancer2::Plugin::OpenAPI;<br>
<br>
my $apiconfig = OpenAPI->get_apiconfig;<br>
<br>
</font>I am using Dancer2 version 0.204001 on Centos 7.3.1611 and
Perl 5.16.3<br>
<br>
When I run this - the plugin config is empty<br>
$VAR1 = {<br>
'pluginconf' => {}<br>
};<br>
<br>
Anyone got any idea what I am doing wrong here ?<br>
<br>
Thanks<br>
Tony<br>
<br>
<br>
</body>
</html>