swagui 0.1.1 → 0.1.2

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: 023033ea0c161ce867c7a46fabc90d0dac05cac2
4
- data.tar.gz: 46963da87b4e990b4f8ecf485844aa8848ecec97
3
+ metadata.gz: 0aeb4e82e294ab2acef6f0f905a5d5190240193d
4
+ data.tar.gz: 1078ce9042532e87e78ab297122723f8cc77dac8
5
5
  SHA512:
6
- metadata.gz: 232abfff9686dcd15518fd398b6954ed12d287d46e8aa67086c40ad698001706dafa2db9649af5ed15bc20d4f5e4c9420f1c15787df2bf49677dbae8045274ba
7
- data.tar.gz: a81e3d6c0adccc86cd42c9f116526156ec0e15e72daa453f4d3ae670892aacd070747b1888964973c5553a60a5109188ff9ee4b61c96e61f4d4f60ee531e1b24
6
+ metadata.gz: 79b53723736615a736208b9773ef6262f612dbd9c61ed860e64ed87c5683e88de13fb3ce06996ec9e4a8175283e48359c323e95f204d137985f54b836f29b237
7
+ data.tar.gz: 4ff8496c3a6834ebabf898fe2c217a0cc6041eec362282ee6bf8af5b862ece69c561fdf23356001a257a40833b3ce0506f49d91cd8d26f0203c00166ab39ca67
data/README.md CHANGED
@@ -25,6 +25,13 @@ end
25
25
 
26
26
  * `url`: the url path to access the [swagger-ui].
27
27
  * `path`: the sub-directory name where the swagger files are stored. It assumes that `api-docs` is the index file in the directory.
28
+ * basic auth block: in case the doc site need to be protected by http basic auth, you can configure it by a block, for example:
29
+
30
+ ```ruby
31
+ use Swagui::App, url: '/doc', path: 'doc' do |username, password|
32
+ [username, password] == ['admin', 'admin']
33
+ end
34
+ ```
28
35
 
29
36
  You will be able to access the [swagger-ui] loaded with your api documentation at `/doc` (your `url` setting) when the server starts.
30
37
 
@@ -13,16 +13,9 @@ module Swagui
13
13
  def call(env)
14
14
  path = env["PATH_INFO"].gsub(@url_regex, '') # root path renders index.html
15
15
 
16
- env['HTTP_IF_MODIFIED_SINCE'] = nil # not 304s
16
+ response = first_valid_file_response(path) || [404, {"Content-Type"=>"application/json"}, '']
17
17
 
18
- response = [404, {"Content-Type"=>"application/json"}, '']
19
- extension = ['', '.json', '.yml'].find do |ext|
20
- response = @app_file_server.call(env.dup.merge!('PATH_INFO' => "#{path}#{ext}"))
21
- response[0] == 200
22
- end
23
-
24
- # handles yaml parsing
25
- if extension == '.yml'
18
+ if response[2].path.end_with?('.yml') # yml response needs to be re=processed.
26
19
  body = ''
27
20
  response[2].each {|f| body = YAML::load(f).to_json}
28
21
  response[2] = [body]
@@ -33,5 +26,13 @@ module Swagui
33
26
 
34
27
  response
35
28
  end
29
+
30
+ private
31
+
32
+ def first_valid_file_response(path)
33
+ ['', '.json', '.yml'].map do |ext|
34
+ @app_file_server.call('PATH_INFO' => "#{path}#{ext}", 'REQUEST_METHOD' => 'GET')
35
+ end.find {|res| res[0] == 200 }
36
+ end
36
37
  end
37
38
  end
@@ -1,3 +1,3 @@
1
1
  module Swagui
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Xu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-13 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack