swaggard 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +57 -0
- data/app/assets/javascripts/swaggard/swaggard.js +4 -0
- data/app/controllers/swaggard/swagger_controller.rb +27 -2
- data/app/views/swaggard/swagger/index.html.erb +4 -0
- data/lib/swaggard/configuration.rb +18 -1
- data/lib/swaggard/version.rb +2 -2
- data/lib/tasks/swaggard.rake +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 975a235818d6db49cd7fa682097786bdddea1ca0
|
4
|
+
data.tar.gz: ce7d4e6e8445fdb0657328b8b43a5f98a5008758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5eb07c84cbc3eda2e169ed70b9b08ab6615ce3bf2e58d0c5d9f7fba32a2f181ff8f1e488369e3e316c438b3d021e8873f1a2a58621a7e5d5c5308e3671fca7
|
7
|
+
data.tar.gz: bac879d907aea3d434b852c4cb701efa2a243d82152d5ecbdf362bcc75fe25e4c7a30b684999291cc0f2d79efc560658c3eacc99a98840889d9a00b069f9aa79
|
data/README.md
CHANGED
@@ -175,6 +175,63 @@ You can configure it as follows:
|
|
175
175
|
|
176
176
|
Even if you provide a authentication_value you can later change it from the ui.
|
177
177
|
|
178
|
+
Access authorization
|
179
|
+
--------------
|
180
|
+
|
181
|
+
Swaggard supports access authorization.
|
182
|
+
|
183
|
+
You can configure it as follows:
|
184
|
+
|
185
|
+
# config/initializers/swaggard.rb
|
186
|
+
Swaggard.configure do |config|
|
187
|
+
config.access_username = 'admin'
|
188
|
+
config.access_password = 'password'
|
189
|
+
end
|
190
|
+
|
191
|
+
If you not set `access_username`, everyone will have access to Swagger documentation.
|
192
|
+
|
193
|
+
Default content type
|
194
|
+
--------------
|
195
|
+
|
196
|
+
You can set default content type in Swaggard configuration as follows:
|
197
|
+
|
198
|
+
# config/initializers/swaggard.rb
|
199
|
+
Swaggard.configure do |config|
|
200
|
+
config.default_content_type = 'application/json'
|
201
|
+
end
|
202
|
+
|
203
|
+
If you set `default_content_type`, Swagger will use it in example request.
|
204
|
+
|
205
|
+
Caching
|
206
|
+
--------------
|
207
|
+
|
208
|
+
You can improve Swagger performance by using caching. You can enable `use_cache` in Swaggard configuration as follows:
|
209
|
+
|
210
|
+
# config/initializers/swaggard.rb
|
211
|
+
Swaggard.configure do |config|
|
212
|
+
config.use_cache = Rails.env.production?
|
213
|
+
end
|
214
|
+
|
215
|
+
If you set `use_cache` as `Rails.env.production?`, Swagger will use cache only in production mode.
|
216
|
+
|
217
|
+
Note. For cache clearing you can execute `rake swaggard:clear_cache`.
|
218
|
+
|
219
|
+
Documentation Scoping
|
220
|
+
---------------------
|
221
|
+
Its possible to only generate Swagger documentation for a subset of your application controllers
|
222
|
+
to do this you just need to use the `controllers_path` config option.
|
223
|
+
For instance to only generate documentation for the controllers under `app/controllers/api` you
|
224
|
+
need do this:
|
225
|
+
|
226
|
+
# config/initializers/swaggard.rb
|
227
|
+
Swaggard.configure do |config|
|
228
|
+
...
|
229
|
+
config.controllers_path = "#{Rails.root}/app/controllers/api/**/*.rb"
|
230
|
+
...
|
231
|
+
end
|
232
|
+
|
233
|
+
The default value for `controllers_path` is `"#{Rails.root}/app/controllers/**/*.rb"`.
|
234
|
+
|
178
235
|
More Information
|
179
236
|
-----------------
|
180
237
|
|
@@ -21,6 +21,10 @@ $(function () {
|
|
21
21
|
$('pre code').each(function(i, e) {
|
22
22
|
hljs.highlightBlock(e)
|
23
23
|
});
|
24
|
+
|
25
|
+
// set default content type
|
26
|
+
$('select[name="responseContentType"]').val(window.default_content_type);
|
27
|
+
$('select[name="parameterContentType"]').val(window.default_content_type);
|
24
28
|
},
|
25
29
|
onFailure: function(data) {
|
26
30
|
log("Unable to Load SwaggerUI");
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Swaggard
|
2
2
|
class SwaggerController < ApplicationController
|
3
3
|
|
4
|
+
before_filter :authorize
|
5
|
+
|
4
6
|
def index
|
5
7
|
respond_to do |format|
|
6
8
|
format.html do
|
@@ -8,16 +10,39 @@ module Swaggard
|
|
8
10
|
@authentication_key = Swaggard.configuration.authentication_key
|
9
11
|
@authentication_value = Swaggard.configuration.authentication_value
|
10
12
|
|
11
|
-
render :index
|
13
|
+
render :index, layout: false
|
12
14
|
end
|
13
15
|
|
14
16
|
format.json do
|
15
|
-
doc =
|
17
|
+
doc = get_swaggard_doc
|
16
18
|
|
17
19
|
render json: doc
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
protected
|
25
|
+
|
26
|
+
def authorize
|
27
|
+
unless Swaggard.configuration.access_username.blank?
|
28
|
+
authenticate_or_request_with_http_basic do |username, password|
|
29
|
+
username == Swaggard.configuration.access_username && password == Swaggard.configuration.access_password
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_swaggard_doc
|
35
|
+
if Swaggard.configuration.use_cache
|
36
|
+
doc = Rails.cache.fetch('swagger_doc')
|
37
|
+
if doc.blank?
|
38
|
+
doc = Swaggard.get_doc(request.host_with_port)
|
39
|
+
Rails.cache.write('swagger_doc', doc)
|
40
|
+
end
|
41
|
+
doc
|
42
|
+
else
|
43
|
+
Swaggard.get_doc(request.host_with_port)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
22
47
|
end
|
23
48
|
end
|
@@ -10,6 +10,10 @@
|
|
10
10
|
<%= stylesheet_link_tag 'swaggard/application_print', media: :print %>
|
11
11
|
<%= javascript_include_tag 'swaggard/application' %>
|
12
12
|
|
13
|
+
<%= javascript_tag do %>
|
14
|
+
window.default_content_type = '<%= Swaggard.configuration.default_content_type %>';
|
15
|
+
<% end %>
|
16
|
+
|
13
17
|
</head>
|
14
18
|
|
15
19
|
<body class='swagger-section'>
|
@@ -16,7 +16,8 @@ module Swaggard
|
|
16
16
|
|
17
17
|
attr_writer :swagger_version, :api_base_path, :api_version, :api_path, :api_formats, :title,
|
18
18
|
:description, :tos, :contact_email, :contact_name, :contact_url, :host,
|
19
|
-
:authentication_type, :authentication_key, :authentication_value
|
19
|
+
:authentication_type, :authentication_key, :authentication_value,
|
20
|
+
:access_username, :access_password, :default_content_type, :use_cache
|
20
21
|
|
21
22
|
def swagger_version
|
22
23
|
@swagger_version ||= '2.0'
|
@@ -90,5 +91,21 @@ module Swaggard
|
|
90
91
|
@authentication_value ||= ''
|
91
92
|
end
|
92
93
|
|
94
|
+
def access_username
|
95
|
+
@access_username ||= ''
|
96
|
+
end
|
97
|
+
|
98
|
+
def access_password
|
99
|
+
@access_password ||= ''
|
100
|
+
end
|
101
|
+
|
102
|
+
def default_content_type
|
103
|
+
@default_content_type ||= ''
|
104
|
+
end
|
105
|
+
|
106
|
+
def use_cache
|
107
|
+
@use_cache ||= false
|
108
|
+
end
|
109
|
+
|
93
110
|
end
|
94
111
|
end
|
data/lib/swaggard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swaggard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/swaggard/swagger/tag.rb
|
170
170
|
- lib/swaggard/swagger/type.rb
|
171
171
|
- lib/swaggard/version.rb
|
172
|
+
- lib/tasks/swaggard.rake
|
172
173
|
- spec/fixtures/api.json
|
173
174
|
- spec/fixtures/dummy/app/controllers/admin/pets_controller.rb
|
174
175
|
- spec/fixtures/dummy/app/controllers/application_controller.rb
|