miniswag-ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/lib/generators/miniswag/ui/custom/custom_generator.rb +15 -0
- data/lib/generators/miniswag/ui/install/install_generator.rb +19 -0
- data/lib/generators/miniswag/ui/install/templates/miniswag_ui.rb +14 -0
- data/lib/miniswag/ui/basic_auth.rb +30 -0
- data/lib/miniswag/ui/configuration.rb +42 -0
- data/lib/miniswag/ui/engine.rb +23 -0
- data/lib/miniswag/ui/index.erb +35 -0
- data/lib/miniswag/ui/middleware.rb +56 -0
- data/lib/miniswag/ui.rb +16 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 21053b8d93bdb4c2d156e98cb6d57ca46fa20f7f68335d94d1bacdbd375aaf28
|
|
4
|
+
data.tar.gz: 79f2201b7412895ca8b9f5ca21acc74606a135b0db8212a3c19ccdbc108397d1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '066339385b6211cd36a5b701a7aa45a19be4072eeb17ae93b6af36ea5f29ebcb558fad884ffd2dd64c3fbc823c26baf4ebf60464dd0748da17849c6a484076c3'
|
|
7
|
+
data.tar.gz: 1044084f8f24fa858d4ca43e9e02691981010eb377721a3c7529ef895df946dddac17dd54b91b01f944af99a71f831ddbdc95b10dd18d5a5393fb63ca6435778
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sika
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
module Miniswag
|
|
6
|
+
module Ui
|
|
7
|
+
class CustomGenerator < Rails::Generators::Base
|
|
8
|
+
source_root File.expand_path('../../../../../lib/miniswag/ui', __dir__)
|
|
9
|
+
|
|
10
|
+
def add_custom_index
|
|
11
|
+
copy_file('index.erb', 'app/views/miniswag/ui/home/index.html.erb')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
module Miniswag
|
|
6
|
+
module Ui
|
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
|
9
|
+
|
|
10
|
+
def add_initializer
|
|
11
|
+
template('miniswag_ui.rb', 'config/initializers/miniswag_ui.rb')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_routes
|
|
15
|
+
route("mount Miniswag::Ui::Engine => '/api-docs'")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Miniswag::Ui.configure do |c|
|
|
4
|
+
# List the OpenAPI endpoints that you want to be documented through the
|
|
5
|
+
# swagger-ui. The first parameter is the path (absolute or relative to the UI
|
|
6
|
+
# host) to the corresponding endpoint and the second is a title that will be
|
|
7
|
+
# displayed in the document selector.
|
|
8
|
+
|
|
9
|
+
c.openapi_endpoint '/api-docs/v1/openapi.yaml', 'API V1 Docs'
|
|
10
|
+
|
|
11
|
+
# Add Basic Auth in case your API is private
|
|
12
|
+
# c.basic_auth_enabled = true
|
|
13
|
+
# c.basic_auth_credentials 'username', 'password'
|
|
14
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rack/auth/basic'
|
|
4
|
+
|
|
5
|
+
module Miniswag
|
|
6
|
+
module Ui
|
|
7
|
+
# Extend Rack HTTP Basic Authentication, as per RFC 2617.
|
|
8
|
+
# @api private
|
|
9
|
+
class BasicAuth < ::Rack::Auth::Basic
|
|
10
|
+
def call(env)
|
|
11
|
+
return @app.call(env) unless env_matching_path(env)
|
|
12
|
+
|
|
13
|
+
super(env)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def env_matching_path(env)
|
|
19
|
+
path = base_path(env['PATH_INFO'])
|
|
20
|
+
Miniswag::Ui.config.config_object[:urls]&.find do |endpoint|
|
|
21
|
+
base_path(endpoint[:url]) == path
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def base_path(url)
|
|
26
|
+
url.downcase.split('/')[1]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rack'
|
|
4
|
+
|
|
5
|
+
module Miniswag
|
|
6
|
+
module Ui
|
|
7
|
+
class Configuration
|
|
8
|
+
attr_reader :template_locations, :assets_root
|
|
9
|
+
attr_accessor :basic_auth_enabled, :config_object, :oauth_config_object
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@template_locations = [
|
|
13
|
+
# preferred override location
|
|
14
|
+
"#{Rack::Directory.new('').root}/swagger/index.erb",
|
|
15
|
+
# backwards compatible override location
|
|
16
|
+
"#{Rack::Directory.new('').root}/app/views/miniswag/ui/home/index.html.erb",
|
|
17
|
+
# default location
|
|
18
|
+
File.expand_path('index.erb', __dir__)
|
|
19
|
+
]
|
|
20
|
+
@assets_root = File.expand_path('../../../node_modules/swagger-ui-dist', __dir__)
|
|
21
|
+
@config_object = {}
|
|
22
|
+
@oauth_config_object = {}
|
|
23
|
+
@basic_auth_enabled = false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def openapi_endpoint(url, name)
|
|
27
|
+
@config_object[:urls] ||= []
|
|
28
|
+
@config_object[:urls] << { url: url, name: name }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def basic_auth_credentials(username, password)
|
|
32
|
+
@config_object[:basic_auth] = { username: username, password: password }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# rubocop:disable Naming/AccessorMethodName
|
|
36
|
+
def get_binding
|
|
37
|
+
binding
|
|
38
|
+
end
|
|
39
|
+
# rubocop:enable Naming/AccessorMethodName
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'miniswag/ui/middleware'
|
|
4
|
+
require 'miniswag/ui/basic_auth'
|
|
5
|
+
|
|
6
|
+
module Miniswag
|
|
7
|
+
module Ui
|
|
8
|
+
class Engine < ::Rails::Engine
|
|
9
|
+
isolate_namespace Miniswag::Ui
|
|
10
|
+
|
|
11
|
+
initializer 'miniswag-ui.initialize' do |app|
|
|
12
|
+
middleware.use Miniswag::Ui::Middleware, Miniswag::Ui.config
|
|
13
|
+
|
|
14
|
+
if Miniswag::Ui.config.basic_auth_enabled
|
|
15
|
+
c = Miniswag::Ui.config
|
|
16
|
+
app.middleware.use Miniswag::Ui::BasicAuth do |username, password|
|
|
17
|
+
c.config_object[:basic_auth].values == [username, password]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!-- HTML for Swagger UI -->
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Miniswag API Documentation</title>
|
|
7
|
+
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
|
8
|
+
<style>
|
|
9
|
+
html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; }
|
|
10
|
+
*, *:before, *:after { box-sizing: inherit; }
|
|
11
|
+
body { margin:0; background: #fafafa; }
|
|
12
|
+
</style>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<div id="swagger-ui"></div>
|
|
16
|
+
<script src="./swagger-ui-bundle.js"> </script>
|
|
17
|
+
<script src="./swagger-ui-standalone-preset.js"> </script>
|
|
18
|
+
<script>
|
|
19
|
+
window.onload = function() {
|
|
20
|
+
var configObject = JSON.parse('<%= config_object.to_json %>');
|
|
21
|
+
var oauthConfigObject = JSON.parse('<%= oauth_config_object.to_json %>');
|
|
22
|
+
|
|
23
|
+
// Apply defaults
|
|
24
|
+
configObject.dom_id = "#swagger-ui";
|
|
25
|
+
configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
|
|
26
|
+
configObject.layout = "StandaloneLayout";
|
|
27
|
+
|
|
28
|
+
const ui = SwaggerUIBundle(configObject);
|
|
29
|
+
if (Object.keys(oauthConfigObject).length) {
|
|
30
|
+
ui.initOAuth(oauthConfigObject);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Miniswag
|
|
4
|
+
module Ui
|
|
5
|
+
class Middleware < Rack::Static
|
|
6
|
+
def initialize(app, config)
|
|
7
|
+
@config = config
|
|
8
|
+
super(app, urls: [''], root: config.assets_root)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(env)
|
|
12
|
+
if base_path?(env)
|
|
13
|
+
redirect_uri = "#{env['SCRIPT_NAME'].chomp('/')}/index.html"
|
|
14
|
+
return [301, { 'Location' => redirect_uri }, []]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if index_path?(env)
|
|
18
|
+
return [200, { 'Content-Type' => 'text/html', 'Content-Security-Policy' => csp },
|
|
19
|
+
[render_template]]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def base_path?(env)
|
|
28
|
+
env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == '/'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def index_path?(env)
|
|
32
|
+
env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == '/index.html'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def render_template
|
|
36
|
+
file = File.new(template_filename)
|
|
37
|
+
template = ERB.new(file.read)
|
|
38
|
+
template.result(@config.get_binding)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def template_filename
|
|
42
|
+
@config.template_locations.find { |filename| File.exist?(filename) }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def csp
|
|
46
|
+
<<~POLICY.tr("\n", ' ')
|
|
47
|
+
default-src 'self';
|
|
48
|
+
img-src 'self' data: https://validator.swagger.io;
|
|
49
|
+
font-src 'self' https://fonts.gstatic.com;
|
|
50
|
+
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
|
|
51
|
+
script-src 'self' 'unsafe-inline';
|
|
52
|
+
POLICY
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/miniswag/ui.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'miniswag/ui/configuration'
|
|
4
|
+
require 'miniswag/ui/engine'
|
|
5
|
+
|
|
6
|
+
module Miniswag
|
|
7
|
+
module Ui
|
|
8
|
+
def self.configure
|
|
9
|
+
yield(config)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.config
|
|
13
|
+
@config ||= Configuration.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: miniswag-ui
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Edem Kumodzi
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: actionpack
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '9.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '7.0'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '9.0'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: railties
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '7.0'
|
|
39
|
+
- - "<"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '9.0'
|
|
42
|
+
type: :runtime
|
|
43
|
+
prerelease: false
|
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '7.0'
|
|
49
|
+
- - "<"
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '9.0'
|
|
52
|
+
description: |
|
|
53
|
+
Generate beautiful API documentation, including a UI to explore and test
|
|
54
|
+
operations, directly from your Minitest integration tests.
|
|
55
|
+
email:
|
|
56
|
+
- edem@sika.io
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- MIT-LICENSE
|
|
62
|
+
- lib/generators/miniswag/ui/custom/custom_generator.rb
|
|
63
|
+
- lib/generators/miniswag/ui/install/install_generator.rb
|
|
64
|
+
- lib/generators/miniswag/ui/install/templates/miniswag_ui.rb
|
|
65
|
+
- lib/miniswag/ui.rb
|
|
66
|
+
- lib/miniswag/ui/basic_auth.rb
|
|
67
|
+
- lib/miniswag/ui/configuration.rb
|
|
68
|
+
- lib/miniswag/ui/engine.rb
|
|
69
|
+
- lib/miniswag/ui/index.erb
|
|
70
|
+
- lib/miniswag/ui/middleware.rb
|
|
71
|
+
homepage: https://github.com/edemkumodzi/miniswag
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata:
|
|
75
|
+
source_code_uri: https://github.com/edemkumodzi/miniswag/tree/main/miniswag-ui
|
|
76
|
+
rubygems_mfa_required: 'true'
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '3.1'
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubygems_version: 3.7.0
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: A Rails Engine that includes swagger-ui and powers it from configured OpenAPI
|
|
94
|
+
endpoints
|
|
95
|
+
test_files: []
|