swagger_ui_engine 1.0.2 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cf6d187a04a511f68f0ca2aaf44e67a191a8abb
4
- data.tar.gz: 551be9c6c59e67202c69c8dc8bf17341a75c9079
3
+ metadata.gz: feeab22e987c76c54281622b493aa6a56c8adab3
4
+ data.tar.gz: a318d182ec2bb18add9decae5e6df03f7ce5a52d
5
5
  SHA512:
6
- metadata.gz: 99d13298d35bab586e706419f30787b107add39656328cf9644376784317ba611d9fff076338a360edff3e9558ffe2ba525c95dee08020160a2419d4b5fb82f9
7
- data.tar.gz: 1be044e1b3c8f8152801ad9f70a6e711bb3dd48d498695028671b3ed153f4582f21581f6ae61ef5a6097d9b72fcc3a0ed8b534b0f1f6f24f8fdc8971757c085a
6
+ metadata.gz: ae10fc9280d2112315e4623d2ed189a1f1090834ee27f108da5a049add052e01c8fb758265f1fc73e0313f9412b2b6b82e4d4c5f2babe69a8273e4c74b4e55aa
7
+ data.tar.gz: 818ce3e5688f985c5fbbb291a2263fe0b375fb8cb72521ebb504b613efe62e48ae76d0a7df05281e544da87b1e928197ab863c3eea73eff16c715c5acb8aed20
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.1.0
6
+
7
+ * Correct Oauth template name
8
+ * Add sass/rails dependency for API-only applications
9
+ * Rename routes to be Swagger-specific
10
+ * Separate route for single API docs version
11
+ * Ignore Gemfile.lock file
12
+ * Overall refactor
13
+
5
14
  ## 1.0.2
6
15
 
7
16
  * Fix translation loading error
@@ -0,0 +1,51 @@
1
+ module SwaggerUiEngine
2
+ class SwaggerDocsController < ApplicationController
3
+ include SwaggerUiEngine::ConfigParser
4
+ include SwaggerUiEngine::OauthConfigParser
5
+
6
+ add_template_helper SwaggerUiEngine::TranslationHelper
7
+ layout 'swagger_ui_engine/layouts/swagger', except: %w(oauth2)
8
+
9
+ before_action :set_configs, :set_oauth_configs
10
+
11
+ def oauth2
12
+ end
13
+
14
+ def index
15
+ # backward compatibility for defining single doc url in strings
16
+ redirect_to single_swagger_doc_path if single_doc_url?
17
+ redirect_to swagger_doc_path(@swagger_url.keys.first) if single_doc_url_hash?
18
+ end
19
+
20
+ def show
21
+ @single_doc_url = single_doc_url? || single_doc_url_hash?
22
+ @swagger_url = @swagger_url[params[:id].to_sym] unless single_doc_url?
23
+ end
24
+
25
+ def single_doc
26
+ render 'show'
27
+ end
28
+
29
+ private
30
+
31
+ def set_configs
32
+ SwaggerUiEngine::DEFAULTS.keys.each do |key|
33
+ instance_variable_set("@#{key}", self.send("set_#{key}"))
34
+ end
35
+ end
36
+
37
+ def set_oauth_configs
38
+ SwaggerUiEngine::OAUTH2_DEFAULTS.keys.each do |key|
39
+ instance_variable_set("@#{key}", self.send("set_#{key}"))
40
+ end
41
+ end
42
+
43
+ def single_doc_url?
44
+ @swagger_url.is_a?(String)
45
+ end
46
+
47
+ def single_doc_url_hash?
48
+ @swagger_url.is_a?(Hash) && @swagger_url.size.eql?(1)
49
+ end
50
+ end
51
+ end
@@ -1,34 +1,21 @@
1
1
  module SwaggerUiEngine
2
2
  module ConfigParser
3
- def set_doc_expansion
4
- configuration.doc_expansion || default_doc_expansion
5
- end
6
-
7
- def set_json_editor
8
- configuration.json_editor || default_json_editor
9
- end
10
-
11
- def set_model_rendering
12
- configuration.model_rendering || default_model_rendering
13
- end
14
-
15
- def set_request_headers
16
- configuration.request_headers || default_request_headers
17
- end
18
-
19
- def set_show_operation_ids
20
- configuration.show_operation_ids || default_show_operation_ids
21
- end
3
+ SwaggerUiEngine::DEFAULTS.each do |default|
4
+ next if default.first.to_s.eql?('validator_url')
22
5
 
23
- def set_swagger_url
24
- configuration.swagger_url || default_swagger_url
6
+ define_method("set_#{default.first}") do
7
+ # set_swagger_url set_doc_expansion
8
+ # set_json_editor set_model_rendering
9
+ # set_request_headers
10
+ configuration.send("#{default.first}") || default.last
11
+ end
25
12
  end
26
13
 
27
14
  def set_validator_url
28
- validator_enabled ? default_validator_url : 'null'
15
+ validator_enabled? ? SwaggerUiEngine::DEFAULTS[:validator_url] : 'null'
29
16
  end
30
17
 
31
- def validator_enabled
18
+ def validator_enabled?
32
19
  configuration.validator_enabled || false
33
20
  end
34
21
 
@@ -1,31 +1,12 @@
1
1
  module SwaggerUiEngine
2
2
  module OauthConfigParser
3
- def set_oauth_app_name
4
- configuration.oauth_app_name || 'your-app-name'
5
- end
6
-
7
- def set_oauth_client_id
8
- configuration.oauth_client_id || 'your-client-id'
9
- end
10
-
11
- def set_oauth_client_secret
12
- configuration.oauth_client_secret || 'your-client-secret-if-required'
13
- end
14
-
15
- def set_oauth_realm
16
- configuration.oauth_realm || 'your-realms'
17
- end
18
-
19
- def set_oauth_scope_separator
20
- configuration.oauth_scope_separator || ' '
21
- end
22
-
23
- def set_oauth_query_string_params
24
- configuration.oauth_query_string_params || {}
25
- end
26
-
27
- def configuration
28
- SwaggerUiEngine.configuration
3
+ SwaggerUiEngine::OAUTH2_DEFAULTS.each do |default|
4
+ define_method("set_#{default.first}") do
5
+ # set_oauth_app_name set_oauth_client_id
6
+ # set_oauth_client_secret set_oauth_realm
7
+ # set_oauth_scope_separator set_oauth_query_string_params
8
+ configuration.send("#{default.first}") || default.last
9
+ end
29
10
  end
30
11
  end
31
12
  end
@@ -12,7 +12,7 @@
12
12
 
13
13
  <%= javascript_include_tag "swagger_ui_engine/application" %>
14
14
  <%= csrf_meta_tags %>
15
-
15
+ <%= yield :head %>
16
16
  </head>
17
17
 
18
18
  <body class="swagger-section">
@@ -24,14 +24,7 @@
24
24
 
25
25
  <div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
26
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>
27
+ <%= yield %>
35
28
  </div>
36
29
  </body>
37
30
  </html>
@@ -0,0 +1,8 @@
1
+ <ul>
2
+ <h2> API documentations: </h2>
3
+ <% @swagger_url.each_key do |k| %>
4
+ <li>
5
+ <h1> <%= link_to k, swagger_doc_path(k) %> </h1>
6
+ </li>
7
+ <% end %>
8
+ </ul>
@@ -1,19 +1,4 @@
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
- <%= load_translation_file %>
15
- <%= csrf_meta_tags %>
16
-
1
+ <% content_for(:head) do %>
17
2
  <script type="text/javascript">
18
3
  $(function () {
19
4
  var url = window.location.search.match(/url=([^&]+)/);
@@ -34,7 +19,7 @@
34
19
  window.swaggerUi = new SwaggerUi({
35
20
  url: url,
36
21
  validatorUrl: "<%= @validator_url %>",
37
- oauth2RedirectUrl: "<%= oauth2_docs_path %>",
22
+ oauth2RedirectUrl: "<%= oauth2_swagger_docs_path %>",
38
23
  dom_id: "swagger-ui-container",
39
24
  supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
40
25
  onComplete: function(swaggerApi, swaggerUi){
@@ -72,26 +57,10 @@
72
57
  }
73
58
  });
74
59
  </script>
75
- </head>
76
-
77
- <body class="swagger-section">
78
- <div id='header'>
79
- <div class="swagger-ui-wrap">
80
- <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>
81
- <form id='api_selector'>
82
- <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
83
- <div id='auth_container'></div>
84
- <div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
85
- </form>
86
- </div>
87
- </div>
60
+ <% end %>
88
61
 
89
- <div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
90
- <div id="swagger-ui-container" class="swagger-ui-wrap"></div>
91
- <% unless @single_doc_url %>
92
- <div class="swagger-ui-wrap">
93
- <a href="<%= docs_path %>" class="swagger-return-link" data-sw-translate>Back to the list</a>
94
- </div>
95
- <% end %>
96
- </body>
97
- </html>
62
+ <% unless @single_doc_url %>
63
+ <div class="swagger-ui-wrap">
64
+ <a href="<%= swagger_docs_path %>" class="swagger-return-link" data-sw-translate> Back to the list </a>
65
+ </div>
66
+ <% end %>
@@ -1,11 +1,12 @@
1
1
  SwaggerUiEngine::Engine.routes.draw do
2
2
  scope format: false do
3
- resources :docs, only: [:index, :show] do
3
+ resources :swagger_docs, only: [:index, :show] do
4
4
  collection do
5
- get 'oauth2', to: 'docs#oauth2', format: false
5
+ get 'oauth2', to: 'swagger_docs#oauth2', format: false
6
6
  end
7
7
  end
8
8
 
9
- root to: 'docs#index'
9
+ get 'single_swagger_doc', to: 'swagger_docs#single_doc', format: false
10
+ root to: 'swagger_docs#index'
10
11
  end
11
12
  end
@@ -1,6 +1,7 @@
1
1
  require 'swagger_ui_engine/engine'
2
2
  require 'swagger_ui_engine/version'
3
3
  require 'swagger_ui_engine/configuration'
4
+ require 'swagger_ui_engine/defaults'
4
5
 
5
6
  module SwaggerUiEngine
6
7
  class << self
@@ -1,23 +1,23 @@
1
1
  module SwaggerUiEngine
2
2
  class Configuration
3
3
  # Configurable options
4
- OPTIONS = [
5
- :admin_username,
6
- :admin_password,
7
- :doc_expansion,
8
- :json_editor,
9
- :model_rendering,
10
- :oauth_client_id,
11
- :oauth_client_secret,
12
- :oauth_realm,
13
- :oauth_app_name,
14
- :oauth_scope_separator,
15
- :oauth_query_string_params,
16
- :request_headers,
17
- :swagger_url,
18
- :translator_enabled,
19
- :validator_enabled,
20
- ].freeze
4
+ OPTIONS = %i(
5
+ admin_username
6
+ admin_password
7
+ doc_expansion
8
+ json_editor
9
+ model_rendering
10
+ oauth_client_id
11
+ oauth_client_secret
12
+ oauth_realm
13
+ oauth_app_name
14
+ oauth_scope_separator
15
+ oauth_query_string_params
16
+ request_headers
17
+ swagger_url
18
+ translator_enabled
19
+ validator_enabled
20
+ ).freeze
21
21
 
22
22
  attr_accessor(*OPTIONS)
23
23
  end
@@ -0,0 +1,19 @@
1
+ module SwaggerUiEngine
2
+ DEFAULTS = {
3
+ swagger_url: 'http://petstore.swagger.io/v2/swagger.json',
4
+ doc_expansion: 'none',
5
+ json_editor: false,
6
+ model_rendering: 'schema',
7
+ request_headers: false,
8
+ validator_url: '//online.swagger.io/validator'
9
+ }.freeze
10
+
11
+ OAUTH2_DEFAULTS = {
12
+ oauth_app_name: 'your-app-name',
13
+ oauth_client_id: 'your-client-id',
14
+ oauth_client_secret: 'your-client-secret-if-required',
15
+ oauth_realm: 'your-realms',
16
+ oauth_scope_separator: ' ',
17
+ oauth_query_string_params: {}
18
+ }.freeze
19
+ end
@@ -1,3 +1,5 @@
1
+ require 'sass/rails'
2
+
1
3
  module SwaggerUiEngine
2
4
  class Engine < ::Rails::Engine
3
5
  isolate_namespace SwaggerUiEngine
@@ -1,4 +1,4 @@
1
1
  module SwaggerUiEngine
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  SWAGGER_UI_VERSION = '2.2.10'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagger_ui_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.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-06-02 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: sass-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  description: Mount Swagger UI web console as Rails engine, configure it as you want
34
48
  and write your API documentation in simple YAML files.
35
49
  email:
@@ -98,18 +112,19 @@ files:
98
112
  - app/assets/stylesheets/swagger_ui_engine/lib/typography.css.erb
99
113
  - app/assets/stylesheets/swagger_ui_engine/print.css
100
114
  - app/controllers/swagger_ui_engine/application_controller.rb
101
- - app/controllers/swagger_ui_engine/docs_controller.rb
115
+ - app/controllers/swagger_ui_engine/swagger_docs_controller.rb
102
116
  - app/helpers/swagger_ui_engine/auth_config_parser.rb
103
117
  - app/helpers/swagger_ui_engine/config_parser.rb
104
118
  - app/helpers/swagger_ui_engine/oauth_config_parser.rb
105
- - app/helpers/swagger_ui_engine/swagger_ui_defaults.rb
106
119
  - app/helpers/swagger_ui_engine/translation_helper.rb
107
- - app/views/swagger_ui_engine/docs/index.html.erb
108
- - app/views/swagger_ui_engine/docs/ouath2.html.erb
109
- - app/views/swagger_ui_engine/docs/show.html.erb
120
+ - app/views/swagger_ui_engine/layouts/swagger.html.erb
121
+ - app/views/swagger_ui_engine/swagger_docs/index.html.erb
122
+ - app/views/swagger_ui_engine/swagger_docs/oauth2.html.erb
123
+ - app/views/swagger_ui_engine/swagger_docs/show.html.erb
110
124
  - config/routes.rb
111
125
  - lib/swagger_ui_engine.rb
112
126
  - lib/swagger_ui_engine/configuration.rb
127
+ - lib/swagger_ui_engine/defaults.rb
113
128
  - lib/swagger_ui_engine/engine.rb
114
129
  - lib/swagger_ui_engine/version.rb
115
130
  homepage: https://github.com/ZuzannaSt/swagger_ui_engine
@@ -132,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
147
  version: '0'
133
148
  requirements: []
134
149
  rubyforge_project:
135
- rubygems_version: 2.4.5
150
+ rubygems_version: 2.6.11
136
151
  signing_key:
137
152
  specification_version: 4
138
153
  summary: Mountable Rails engine that serves Swagger UI for your API documentation
@@ -1,52 +0,0 @@
1
- module SwaggerUiEngine
2
- class DocsController < ApplicationController
3
- include SwaggerUiEngine::ConfigParser
4
- include SwaggerUiEngine::OauthConfigParser
5
- include SwaggerUiEngine::SwaggerUiDefaults
6
-
7
- add_template_helper SwaggerUiEngine::TranslationHelper
8
- before_action :set_configs, :set_oauth_configs
9
-
10
- def oauth2
11
- end
12
-
13
- def index
14
- # backward compatibility for defining single doc url in strings
15
- redirect_to doc_path('v1') if single_doc_url?
16
- redirect_to doc_path(@swagger_url.keys.first) if single_doc_url_hash?
17
- end
18
-
19
- def show
20
- @single_doc_url = single_doc_url? || single_doc_url_hash?
21
- @swagger_url = @swagger_url[params[:id].to_sym] unless single_doc_url?
22
- end
23
-
24
- private
25
-
26
- def set_configs
27
- @doc_expansion = set_doc_expansion
28
- @json_editor = set_json_editor
29
- @model_rendering = set_model_rendering
30
- @request_headers = set_request_headers
31
- @swagger_url = set_swagger_url
32
- @validator_url = set_validator_url
33
- end
34
-
35
- def set_oauth_configs
36
- @oauth_app_name = set_oauth_app_name
37
- @oauth_client_id = set_oauth_client_id
38
- @oauth_client_secret = set_oauth_client_secret
39
- @oauth_realm = set_oauth_realm
40
- @oauth_query_string_params = set_oauth_query_string_params
41
- @oauth_scope_separator = set_oauth_scope_separator
42
- end
43
-
44
- def single_doc_url?
45
- @swagger_url.is_a?(String)
46
- end
47
-
48
- def single_doc_url_hash?
49
- @swagger_url.is_a?(Hash) && @swagger_url.size == 1
50
- end
51
- end
52
- end
@@ -1,27 +0,0 @@
1
- module SwaggerUiEngine
2
- module SwaggerUiDefaults
3
- def default_swagger_url
4
- 'http://petstore.swagger.io/v2/swagger.json'
5
- end
6
-
7
- def default_doc_expansion
8
- 'none'
9
- end
10
-
11
- def default_json_editor
12
- false
13
- end
14
-
15
- def default_model_rendering
16
- 'schema'
17
- end
18
-
19
- def default_request_headers
20
- false
21
- end
22
-
23
- def default_validator_url
24
- '//online.swagger.io/validator'
25
- end
26
- end
27
- end