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 +4 -4
- data/README.md +7 -0
- data/lib/swagui/swagger_doc_handler.rb +10 -9
- data/lib/swagui/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aeb4e82e294ab2acef6f0f905a5d5190240193d
|
4
|
+
data.tar.gz: 1078ce9042532e87e78ab297122723f8cc77dac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
16
|
+
response = first_valid_file_response(path) || [404, {"Content-Type"=>"application/json"}, '']
|
17
17
|
|
18
|
-
response
|
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
|
data/lib/swagui/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|