swagger_ui_engine 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/app/controllers/swagger_ui_engine/application_controller.rb +20 -0
- data/app/controllers/swagger_ui_engine/docs_controller.rb +25 -2
- data/app/helpers/auth_config_parser.rb +17 -0
- data/app/helpers/config_parser.rb +16 -8
- data/app/helpers/swagger_ui_defaults.rb +4 -0
- data/app/views/swagger_ui_engine/docs/index.html.erb +34 -86
- data/app/views/swagger_ui_engine/docs/show.html.erb +90 -0
- data/config/routes.rb +4 -1
- data/lib/swagger_ui_engine/configuration.rb +17 -0
- data/lib/swagger_ui_engine/engine.rb +0 -17
- data/lib/swagger_ui_engine/version.rb +1 -1
- data/lib/swagger_ui_engine.rb +14 -1
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d6fff974d9f7d8667215be02d2b198551fe8b80
|
4
|
+
data.tar.gz: 0ff2b58a74369dabfb951a7e9c385eca9fc0e13a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 777136dcf3369e1a715f32e91281eeb0f6ac2101811df40208da9595233fe17007dd313ab0bb1e77c8612a8b6df9583e9d9309eedcfac6a11438ae0773be9659
|
7
|
+
data.tar.gz: 96779d30916340800fb2f3766009f49aa7b2a28c0ca8a8b2c5fdc8599f1adb8ba0b258dd35ec55ef5f9b8f2e60a357ecb39273a9fa3b7889b5a4eb6aa8d71ada
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# SwaggerUiEngine Changelog
|
2
|
+
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 0.0.5
|
6
|
+
|
7
|
+
* Support Swagger UI version 2.2.10
|
8
|
+
* Add tests
|
9
|
+
* Fix fonts not being loaded
|
10
|
+
* Describe problem solved by this gem in README
|
11
|
+
|
12
|
+
## 0.0.4
|
13
|
+
|
14
|
+
* Improve configurable options
|
15
|
+
* Fix assets errors
|
16
|
+
|
17
|
+
## 0.0.1-0.0.3
|
18
|
+
|
19
|
+
Initial releases supporting Swagger UI version 2.2.8
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SwaggerUiEngine
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
include AuthConfigParser
|
4
|
+
|
5
|
+
protect_from_forgery with: :exception
|
6
|
+
layout false
|
7
|
+
|
8
|
+
before_action :authenticate_admin
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def authenticate_admin
|
13
|
+
return unless basic_authentication_enabled?
|
14
|
+
|
15
|
+
authenticate_or_request_with_http_basic do |username, password|
|
16
|
+
username == admin_username && password == admin_password
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,14 +1,37 @@
|
|
1
1
|
module SwaggerUiEngine
|
2
|
-
class DocsController <
|
2
|
+
class DocsController < ApplicationController
|
3
3
|
include ConfigParser
|
4
4
|
include SwaggerUiDefaults
|
5
5
|
|
6
|
+
before_action :set_configs
|
7
|
+
|
6
8
|
def index
|
7
|
-
|
9
|
+
# backward compatibility for defining single doc url in strings
|
10
|
+
redirect_to doc_path('v1') if single_doc_url?
|
11
|
+
redirect_to doc_path(@swagger_url.keys.first) if single_doc_url_hash?
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@swagger_url = @swagger_url[params[:id].to_sym] unless single_doc_url?
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def set_configs
|
8
21
|
@doc_expansion = set_doc_expansion
|
9
22
|
@json_editor = set_json_editor
|
10
23
|
@model_rendering = set_model_rendering
|
11
24
|
@request_headers = set_request_headers
|
25
|
+
@swagger_url = set_swagger_url
|
26
|
+
@validator_url = set_validator_url
|
27
|
+
end
|
28
|
+
|
29
|
+
def single_doc_url?
|
30
|
+
@swagger_url.is_a?(String)
|
31
|
+
end
|
32
|
+
|
33
|
+
def single_doc_url_hash?
|
34
|
+
@swagger_url.is_a?(Hash) && @swagger_url.size == 1
|
12
35
|
end
|
13
36
|
end
|
14
37
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AuthConfigParser
|
2
|
+
def admin_username
|
3
|
+
configuration.admin_username
|
4
|
+
end
|
5
|
+
|
6
|
+
def admin_password
|
7
|
+
configuration.admin_password
|
8
|
+
end
|
9
|
+
|
10
|
+
def basic_authentication_enabled?
|
11
|
+
admin_username && admin_password
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
SwaggerUiEngine.configuration
|
16
|
+
end
|
17
|
+
end
|
@@ -1,20 +1,16 @@
|
|
1
1
|
module ConfigParser
|
2
|
-
def set_swagger_url
|
3
|
-
configuration.swagger_url || default_swagger_url
|
4
|
-
end
|
5
|
-
|
6
2
|
def set_doc_expansion
|
7
3
|
configuration.doc_expansion || default_doc_expansion
|
8
4
|
end
|
9
5
|
|
10
|
-
def set_model_rendering
|
11
|
-
configuration.model_rendering || default_model_rendering
|
12
|
-
end
|
13
|
-
|
14
6
|
def set_json_editor
|
15
7
|
configuration.json_editor || default_json_editor
|
16
8
|
end
|
17
9
|
|
10
|
+
def set_model_rendering
|
11
|
+
configuration.model_rendering || default_model_rendering
|
12
|
+
end
|
13
|
+
|
18
14
|
def set_request_headers
|
19
15
|
configuration.request_headers || default_request_headers
|
20
16
|
end
|
@@ -23,6 +19,18 @@ module ConfigParser
|
|
23
19
|
configuration.show_operation_ids || default_show_operation_ids
|
24
20
|
end
|
25
21
|
|
22
|
+
def set_swagger_url
|
23
|
+
configuration.swagger_url || default_swagger_url
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_validator_url
|
27
|
+
validator_enabled ? default_validator_url : 'null'
|
28
|
+
end
|
29
|
+
|
30
|
+
def validator_enabled
|
31
|
+
configuration.validator_enabled || false
|
32
|
+
end
|
33
|
+
|
26
34
|
def configuration
|
27
35
|
SwaggerUiEngine.configuration
|
28
36
|
end
|
@@ -1,89 +1,37 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
onComplete: function(swaggerApi, swaggerUi){
|
38
|
-
if(typeof initOAuth == "function") {
|
39
|
-
initOAuth({
|
40
|
-
clientId: "your-client-id",
|
41
|
-
clientSecret: "your-client-secret-if-required",
|
42
|
-
realm: "your-realms",
|
43
|
-
appName: "your-app-name",
|
44
|
-
scopeSeparator: " ",
|
45
|
-
additionalQueryStringParams: {}
|
46
|
-
});
|
47
|
-
}
|
48
|
-
|
49
|
-
if(window.SwaggerTranslator) {
|
50
|
-
window.SwaggerTranslator.translate();
|
51
|
-
}
|
52
|
-
},
|
53
|
-
onFailure: function(data) {
|
54
|
-
log("Unable to Load SwaggerUI");
|
55
|
-
},
|
56
|
-
docExpansion: "<%= @doc_expansion %>",
|
57
|
-
jsonEditor: "<%= @json_editor %>",
|
58
|
-
defaultModelRendering: "<%= @model_rendering %>",
|
59
|
-
showRequestHeaders: "<%= @request_headers %>",
|
60
|
-
showOperationIds: false
|
61
|
-
});
|
62
|
-
|
63
|
-
window.swaggerUi.load();
|
64
|
-
|
65
|
-
function log() {
|
66
|
-
if ('console' in window) {
|
67
|
-
console.log.apply(console, arguments);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
});
|
71
|
-
</script>
|
72
|
-
</head>
|
73
|
-
|
74
|
-
<body class="swagger-section">
|
75
|
-
<div id='header'>
|
76
|
-
<div class="swagger-ui-wrap">
|
77
|
-
<a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="<%= image_path('swagger_ui_engine/logo_small.png') %>" /><span class="logo__title">swagger</span></a>
|
78
|
-
<form id='api_selector'>
|
79
|
-
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
|
80
|
-
<div id='auth_container'></div>
|
81
|
-
<div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
|
82
|
-
</form>
|
83
|
-
</div>
|
84
|
-
</div>
|
85
|
-
|
86
|
-
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
|
87
|
-
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
|
88
|
-
</body>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta http-equiv="x-ua-compatible" content="IE=edge">
|
6
|
+
<title>Swagger UI</title>
|
7
|
+
<link rel="icon" type="image/png" href="<%= image_path('swagger_ui_engine/favicon-32x32.png') %>" sizes="32x32" />
|
8
|
+
<link rel="icon" type="image/png" href="<%= image_path('swagger_ui_engine/favicon-16x16.png') %>" sizes="16x16" />
|
9
|
+
|
10
|
+
<%= stylesheet_link_tag "swagger_ui_engine/application", media: "screen" %>
|
11
|
+
<%= stylesheet_link_tag "swagger_ui_engine/print", media: "print" %>
|
12
|
+
|
13
|
+
<%= javascript_include_tag "swagger_ui_engine/application" %>
|
14
|
+
<%= csrf_meta_tags %>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body class="swagger-section">
|
19
|
+
<div id='header'>
|
20
|
+
<div class="swagger-ui-wrap">
|
21
|
+
<a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="<%= image_path('swagger_ui_engine/logo_small.png') %>" /><span class="logo__title">swagger</span></a>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
|
26
|
+
<div id="swagger-ui-container" class="swagger-ui-wrap">
|
27
|
+
<ul>
|
28
|
+
<h2> API documentations: </h2>
|
29
|
+
<% @swagger_url.each_key do |k| %>
|
30
|
+
<li>
|
31
|
+
<h1> <%= link_to k, doc_path(k) %> </h1>
|
32
|
+
</li>
|
33
|
+
<% end %>
|
34
|
+
</ul>
|
35
|
+
</div>
|
36
|
+
</body>
|
89
37
|
</html>
|
@@ -0,0 +1,90 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta http-equiv="x-ua-compatible" content="IE=edge">
|
6
|
+
<title>Swagger UI</title>
|
7
|
+
<link rel="icon" type="image/png" href="<%= image_path('swagger_ui_engine/favicon-32x32.png') %>" sizes="32x32" />
|
8
|
+
<link rel="icon" type="image/png" href="<%= image_path('swagger_ui_engine/favicon-16x16.png') %>" sizes="16x16" />
|
9
|
+
|
10
|
+
<%= stylesheet_link_tag "swagger_ui_engine/application", media: "screen" %>
|
11
|
+
<%= stylesheet_link_tag "swagger_ui_engine/print", media: "print" %>
|
12
|
+
|
13
|
+
<%= javascript_include_tag "swagger_ui_engine/application" %>
|
14
|
+
<%= csrf_meta_tags %>
|
15
|
+
|
16
|
+
<script type="text/javascript">
|
17
|
+
$(function () {
|
18
|
+
var url = window.location.search.match(/url=([^&]+)/);
|
19
|
+
if (url && url.length > 1) {
|
20
|
+
url = decodeURIComponent(url[1]);
|
21
|
+
} else {
|
22
|
+
url = "<%= @swagger_url %>";
|
23
|
+
}
|
24
|
+
|
25
|
+
hljs.configure({
|
26
|
+
highlightSizeThreshold: 5000
|
27
|
+
});
|
28
|
+
|
29
|
+
// Pre load translate...
|
30
|
+
if(window.SwaggerTranslator) {
|
31
|
+
window.SwaggerTranslator.translate();
|
32
|
+
}
|
33
|
+
window.swaggerUi = new SwaggerUi({
|
34
|
+
url: url,
|
35
|
+
validatorUrl: "<%= @validator_url %>",
|
36
|
+
dom_id: "swagger-ui-container",
|
37
|
+
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
|
38
|
+
onComplete: function(swaggerApi, swaggerUi){
|
39
|
+
if(typeof initOAuth == "function") {
|
40
|
+
initOAuth({
|
41
|
+
clientId: "your-client-id",
|
42
|
+
clientSecret: "your-client-secret-if-required",
|
43
|
+
realm: "your-realms",
|
44
|
+
appName: "your-app-name",
|
45
|
+
scopeSeparator: " ",
|
46
|
+
additionalQueryStringParams: {}
|
47
|
+
});
|
48
|
+
}
|
49
|
+
|
50
|
+
if(window.SwaggerTranslator) {
|
51
|
+
window.SwaggerTranslator.translate();
|
52
|
+
}
|
53
|
+
},
|
54
|
+
onFailure: function(data) {
|
55
|
+
log("Unable to Load SwaggerUI");
|
56
|
+
},
|
57
|
+
docExpansion: "<%= @doc_expansion %>",
|
58
|
+
jsonEditor: "<%= @json_editor %>",
|
59
|
+
defaultModelRendering: "<%= @model_rendering %>",
|
60
|
+
showRequestHeaders: "<%= @request_headers %>",
|
61
|
+
showOperationIds: false
|
62
|
+
});
|
63
|
+
|
64
|
+
window.swaggerUi.load();
|
65
|
+
|
66
|
+
function log() {
|
67
|
+
if ('console' in window) {
|
68
|
+
console.log.apply(console, arguments);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
</script>
|
73
|
+
</head>
|
74
|
+
|
75
|
+
<body class="swagger-section">
|
76
|
+
<div id='header'>
|
77
|
+
<div class="swagger-ui-wrap">
|
78
|
+
<a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="<%= image_path('swagger_ui_engine/logo_small.png') %>" /><span class="logo__title">swagger</span></a>
|
79
|
+
<form id='api_selector'>
|
80
|
+
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
|
81
|
+
<div id='auth_container'></div>
|
82
|
+
<div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
|
83
|
+
</form>
|
84
|
+
</div>
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
|
88
|
+
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
|
89
|
+
</body>
|
90
|
+
</html>
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module SwaggerUiEngine
|
2
|
+
class Configuration
|
3
|
+
# Configurable options
|
4
|
+
OPTIONS = [
|
5
|
+
:admin_username,
|
6
|
+
:admin_password,
|
7
|
+
:doc_expansion,
|
8
|
+
:json_editor,
|
9
|
+
:model_rendering,
|
10
|
+
:request_headers,
|
11
|
+
:swagger_url,
|
12
|
+
:validator_enabled,
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
attr_accessor(*OPTIONS)
|
16
|
+
end
|
17
|
+
end
|
@@ -18,21 +18,4 @@ module SwaggerUiEngine
|
|
18
18
|
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
class Configuration
|
23
|
-
attr_accessor :swagger_url, :doc_expansion, :model_rendering,
|
24
|
-
:json_editor, :request_headers
|
25
|
-
end
|
26
|
-
class << self
|
27
|
-
attr_writer :configuration
|
28
|
-
end
|
29
|
-
|
30
|
-
module_function
|
31
|
-
def configuration
|
32
|
-
@configuration ||= Configuration.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def configure
|
36
|
-
yield(configuration)
|
37
|
-
end
|
38
21
|
end
|
data/lib/swagger_ui_engine.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'swagger_ui_engine/engine'
|
2
|
+
require 'swagger_ui_engine/version'
|
3
|
+
require 'swagger_ui_engine/configuration'
|
2
4
|
|
3
5
|
module SwaggerUiEngine
|
6
|
+
class << self
|
7
|
+
delegate(*Configuration::OPTIONS, to: :configuration)
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield configuration
|
15
|
+
end
|
16
|
+
end
|
4
17
|
end
|
metadata
CHANGED
@@ -1,36 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_ui_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ZuzannaSt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 5.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
description: Swagger
|
32
|
+
version: 5.0.0
|
33
|
+
description: Mount Swagger UI web console as Rails engine, configure it as you want
|
34
|
+
and write your API documentation in simple YAML files.
|
28
35
|
email:
|
29
36
|
- zuzannast@gmail.com
|
30
37
|
executables: []
|
31
38
|
extensions: []
|
32
39
|
extra_rdoc_files: []
|
33
40
|
files:
|
41
|
+
- CHANGELOG.md
|
34
42
|
- MIT-LICENSE
|
35
43
|
- Rakefile
|
36
44
|
- app/assets/fonts/swagger_ui_engine/DroidSans-Bold.ttf
|
@@ -88,12 +96,16 @@ files:
|
|
88
96
|
- app/assets/stylesheets/swagger_ui_engine/lib/style.css
|
89
97
|
- app/assets/stylesheets/swagger_ui_engine/lib/typography.css.erb
|
90
98
|
- app/assets/stylesheets/swagger_ui_engine/print.css
|
99
|
+
- app/controllers/swagger_ui_engine/application_controller.rb
|
91
100
|
- app/controllers/swagger_ui_engine/docs_controller.rb
|
101
|
+
- app/helpers/auth_config_parser.rb
|
92
102
|
- app/helpers/config_parser.rb
|
93
103
|
- app/helpers/swagger_ui_defaults.rb
|
94
104
|
- app/views/swagger_ui_engine/docs/index.html.erb
|
105
|
+
- app/views/swagger_ui_engine/docs/show.html.erb
|
95
106
|
- config/routes.rb
|
96
107
|
- lib/swagger_ui_engine.rb
|
108
|
+
- lib/swagger_ui_engine/configuration.rb
|
97
109
|
- lib/swagger_ui_engine/engine.rb
|
98
110
|
- lib/swagger_ui_engine/version.rb
|
99
111
|
homepage: https://github.com/ZuzannaSt/swagger_ui_engine
|
@@ -119,5 +131,6 @@ rubyforge_project:
|
|
119
131
|
rubygems_version: 2.4.5
|
120
132
|
signing_key:
|
121
133
|
specification_version: 4
|
122
|
-
summary:
|
134
|
+
summary: Mountable Rails engine that serves Swagger UI for your API documentation
|
135
|
+
written in YAML files.
|
123
136
|
test_files: []
|