first initial

This commit is contained in:
2025-03-31 21:54:29 +02:00
commit deee0d3737
33 changed files with 916 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
Package: libsteffen-mojoplug-swaggerui-perl
Version: 0.0.5-2
Section: perl
Priority: optional
Architecture: all
Depends: libmojolicious-perl (>= 9.00)
Installed-Size: 80
Maintainer: Steffen Junge <Steffen.Junge@mlands.com>
Description: Fork von Mojolicious::Plugin::SwaggerUI speziell für steffen

View File

@@ -0,0 +1,27 @@
#!/bin/bash
script=`echo $0 | sed 's/^.*\///'`
echo "$script"
if [ -e ./$script ]; then
workdir=/tmp/$USER\_`pwd | sed 's/^.*\///'`
rm -Rf $workdir/*
mkdir -p $workdir
rsync -Cav ./DEBIAN $workdir/
rsync -Cav ./usr $workdir/
# Version in die startup app.pm eintragen
VER=`grep Version $workdir/DEBIAN/control | cut -d ' ' -f2`
sed -i "s@__VERSION__@$VER@g" $workdir/usr/share/perl5/steffen/MojoPlug/SwaggerUI.pm
echo "Version $VER"
chmod -R g-s $workdir
fakeroot dpkg-deb -b $workdir ./
echo "Installed-Size:"
du -h -k --max-depth=0 $workdir
else
echo Das Script $script muss im aktuellen Verzeichnis liegen!
echo Bitte dorthin wechseln und nochmal probieren.
fi

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

View File

@@ -0,0 +1,52 @@
<html>
<head>
<title><%= $title %></title>
%= stylesheet "/swagger-ui/swagger-ui.css"
% if (defined $favicon) {
<link rel="icon" type="image/png" href=<%= url_for($favicon) %> />
% }
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body
{
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
%= javascript "/swagger-ui/swagger-ui-bundle.js"
%= javascript "/swagger-ui/swagger-ui-standalone-preset.js"
<script>
window.onload = function () {
const ui = SwaggerUIBundle({
url: "<%= url_for($url) %>",
dom_id: '#swagger-ui',
validatorUrl: <%= $validateUrl %>,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: "StandaloneLayout"
})
window.ui = ui
}
</script>
</body>
</html>

View File

@@ -0,0 +1,135 @@
package steffen::MojoPlug::SwaggerUI;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::File qw(path);
use File::ShareDir qw(dist_dir);
our $VERSION = '__VERSION__';
sub register {
my ($self, $app, $config) = @_;
my $prefix = $config->{route} // $app->routes()->any('/swagger-ui');
# --- Configuring the Mojolicious path resolvers
my $resources = path(dist_dir('steffen-MojoPlug-SwaggerUI'))
->child('resources');
push(@{$app->static()->paths()}, $resources->child('public')->to_string());
push(@{$app->renderer()->paths()}, $resources->child('templates')->to_string());
# --- Adding the route
my $url = $config->{url} // '/v1';
my $title = $config->{title} // 'Swagger UI';
my $validateUrl = $config->{validateUrl} // 'null';
my $favicon
= (defined $config->{favicon} and $app->static()->file($config->{favicon}))
? $config->{favicon}
: undef;
$prefix->get(q(/) => { url => $url, title => $title, favicon => $favicon, validateUrl => $validateUrl })
->name('swagger_ui');
$app->log->info(sprintf('REGISTERED: %s V%s', __PACKAGE__, $VERSION)) if $config->{verbose};
return;
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Plugin::SwaggerUI - Swagger UI plugin for Mojolicious
=head1 SYNOPSIS
# Mojolicious Lite
plugin 'SwaggerUI' => {
route => app->routes()->any('/swagger'),
url => '/swagger.json',
};
# Mojolicious Full
$app->plugin(
SwaggerUI => {
route => $app->routes()->any('api'),
url => "/api/v1",
title => "Mojolicious App",
favicon => "/images/favicon.png"
}
);
=head1 DESCRIPTION
The plugin allows you to run the Swagger UI component inside your Mojolicious application.
=begin html
<p>
<img alt="Screenshot"
src="https://gitlab.com/marghidanu/mojolicious-plugin-swaggerui/raw/master/share/images/Screenshot.png?inline=true">
</p>
=end html
=head1 OPTIONS
=head2 route
plugin 'SwaggerUI' => {
route => app()->routes()->any('/swagger')
};
Route for the swagger-ui component. It defaults to a any route on C</swagger-ui>
=head2 url
plugin 'SwaggerUI' => {
url => '/swagger.json'
};
Url for the JSON Swagger specification. It defaults to C</v1>.
B<NOTE:>
L<Mojolicious::Plugin::OpenAPI> can expose the JSON Swagger spec under the base path route.
You can just point the path in her and it will automatically work.
=head2 title
plugin 'SwaggerUI' => {
title => 'Project Title'
};
The HTML title that you want to show on swagger-ui page. Deafult to 'Swagger UI'
=head2 favicon
plugin 'SwaggerUI' => {
favicon => '/images/favicon.png'
};
Favicon which you want to associate with swagger-ui page.
It will be served automatically from a 'public' directory if it exists.
In case of non existence mojolicious default favicon will be displayed.
=head1 AUTHOR
Tudor Marghidanu C<tudor@marghidanu.com>
=head1 CREDITS
Gaurav Rai C<gauravrai7860@gmail.com>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2019, Tudor Marghidanu.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
=cut
__END__