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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 683541ecbfa1ee245ba3b609efe020c394899a30
4
- data.tar.gz: 5b2a999913297cac602d276b305ac4a0910fa32c
3
+ metadata.gz: 6d6fff974d9f7d8667215be02d2b198551fe8b80
4
+ data.tar.gz: 0ff2b58a74369dabfb951a7e9c385eca9fc0e13a
5
5
  SHA512:
6
- metadata.gz: aa32685d104bdf33da1916e699f4ebfc2f0449f28b908cbbc9daa3c408c2998039a1619cd54acf28643211654f895b86488c6aad815f5e9d7fcd0d6474b52e04
7
- data.tar.gz: ee23ee2299dd069f46dab66040e78c8121c7fc42492efa0943b7df2579f857ebe9d92ee43cd59544a6ad34f0fe6400127ab8904a48eea073fbd4492c67bb3026
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 < ActionController::Base
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
- @swagger_url = set_swagger_url
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
@@ -18,4 +18,8 @@ module SwaggerUiDefaults
18
18
  def default_request_headers
19
19
  false
20
20
  end
21
+
22
+ def default_validator_url
23
+ '//online.swagger.io/validator'
24
+ end
21
25
  end
@@ -1,89 +1,37 @@
1
1
  <!DOCTYPE html>
2
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
- dom_id: "swagger-ui-container",
36
- supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
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>&nbsp;</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>&nbsp;</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>&nbsp;</div>
88
+ <div id="swagger-ui-container" class="swagger-ui-wrap"></div>
89
+ </body>
90
+ </html>
data/config/routes.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  SwaggerUiEngine::Engine.routes.draw do
2
- root to: 'docs#index'
2
+ scope format: false do
3
+ resources :docs, only: [:index, :show]
4
+ root to: 'docs#index'
5
+ end
3
6
  end
@@ -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
@@ -1,4 +1,4 @@
1
1
  module SwaggerUiEngine
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  SWAGGER_UI_VERSION = '2.2.10'.freeze
4
4
  end
@@ -1,4 +1,17 @@
1
- require "swagger_ui_engine/engine"
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.5
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-04-18 00:00:00.000000000 Z
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: '0'
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: '0'
27
- description: Swagger API docs and web console for your rails project.
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: Mount Swagger-Ui as Rails engine.
134
+ summary: Mountable Rails engine that serves Swagger UI for your API documentation
135
+ written in YAML files.
123
136
  test_files: []