make swagger-ui follow the scheme of netdisco hosting

This commit is contained in:
Oliver Gorwits
2021-10-05 17:16:38 +01:00
parent 9881af551d
commit 0ee5646fac

View File

@@ -304,7 +304,6 @@ hook 'after' => sub {
my $swagger = Dancer::Plugin::Swagger->instance; my $swagger = Dancer::Plugin::Swagger->instance;
my $swagger_doc = $swagger->doc; my $swagger_doc = $swagger->doc;
$swagger_doc->{schemes} = ['http','https'];
$swagger_doc->{consumes} = 'application/json'; $swagger_doc->{consumes} = 'application/json';
$swagger_doc->{produces} = 'application/json'; $swagger_doc->{produces} = 'application/json';
$swagger_doc->{tags} = [ $swagger_doc->{tags} = [
@@ -330,11 +329,13 @@ $swagger_doc->{security} = [ { APIKeyHeader => [] } ];
my $swagger_base = config->{plugins}->{Swagger}->{ui_url}; my $swagger_base = config->{plugins}->{Swagger}->{ui_url};
get $swagger_base => sub { get $swagger_base => sub {
Dancer::Plugin::Swagger->instance->doc->{schemes} = [ request->scheme ];
redirect uri_for($swagger_base)->path redirect uri_for($swagger_base)->path
. '/?url=' . uri_for('/swagger.json')->path; . '/?url=' . uri_for('/swagger.json')->path;
}; };
get $swagger_base.'/' => sub { get $swagger_base.'/' => sub {
Dancer::Plugin::Swagger->instance->doc->{schemes} = [ request->scheme ];
# user might request /swagger-ui/ initially (Plugin doesn't handle this) # user might request /swagger-ui/ initially (Plugin doesn't handle this)
params->{url} or redirect uri_for($swagger_base)->path; params->{url} or redirect uri_for($swagger_base)->path;
send_file( 'swagger-ui/index.html' ); send_file( 'swagger-ui/index.html' );
@@ -342,6 +343,7 @@ get $swagger_base.'/' => sub {
# omg the plugin uses system_path and we don't want to go there # omg the plugin uses system_path and we don't want to go there
get $swagger_base.'/**' => sub { get $swagger_base.'/**' => sub {
Dancer::Plugin::Swagger->instance->doc->{schemes} = [ request->scheme ];
send_file( join '/', 'swagger-ui', @{ (splat())[0] } ); send_file( join '/', 'swagger-ui', @{ (splat())[0] } );
}; };