swagui 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +1 -1
- data/lib/swagui/middleware.rb +24 -5
- 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: 5ab94a4ed97c6df7d5274224ffcf4da84f6e1367
|
4
|
+
data.tar.gz: 4821b3413d845dbcb2d94cfd4450686cd0264d47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 667c6bac6f78a29211d5d08827bc4563ad7a6afc7adbbd31065d77feb286c6728ceebaf7212e9f4693dfd20733df5772f6be9b711bb3991009053d7d9b26c943
|
7
|
+
data.tar.gz: 67bbada1aa02f87a3a7517b63555b1a522e94b23971fb8cbef142f688db358581cd4f983f2802630ba1cd609282346bde1e15794cbf196e4bf33fcd2d5f1f8e2
|
data/README.md
CHANGED
data/lib/swagui/middleware.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'rack'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
2
4
|
|
3
5
|
module Swagui
|
4
6
|
|
@@ -20,18 +22,35 @@ module Swagui
|
|
20
22
|
|
21
23
|
def call(env)
|
22
24
|
path = env["PATH_INFO"].strip
|
23
|
-
|
24
|
-
if @assets_url_regex.match(path)
|
25
|
+
if @assets_url_regex.match(path) # for assets (css/js) files
|
25
26
|
env["PATH_INFO"] = path.gsub(@assets_url_regex, '')
|
26
27
|
@swagger_ui_file_server.call(env)
|
27
28
|
elsif @url_regex.match(path)
|
28
|
-
path = path.gsub(@url_regex, '')
|
29
|
+
path = path.gsub(@url_regex, '') # root path renders index.html
|
29
30
|
if path == '' || path == '/'
|
30
31
|
env["PATH_INFO"] = 'index.html'
|
31
32
|
@swagger_ui_file_server.call(env)
|
32
33
|
else
|
33
|
-
|
34
|
-
|
34
|
+
|
35
|
+
env['HTTP_IF_MODIFIED_SINCE'] = nil # not 304s
|
36
|
+
|
37
|
+
response = [404, {"Content-Type"=>"application/json"}, '']
|
38
|
+
extension = ['', '.json', '.yml'].find do |ext|
|
39
|
+
response = @app_file_server.call(env.dup.merge!('PATH_INFO' => "#{path}#{ext}"))
|
40
|
+
response[0] == 200
|
41
|
+
end
|
42
|
+
|
43
|
+
# handles yaml parsing
|
44
|
+
if extension == '.yml'
|
45
|
+
body = ''
|
46
|
+
response[2].each {|f| body = YAML::load(f).to_json}
|
47
|
+
response[2] = [body]
|
48
|
+
response[1].merge!("Content-Length"=> body.size.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
response[1].merge!("Content-Type"=>"application/json") # response is always json content
|
52
|
+
|
53
|
+
response
|
35
54
|
end
|
36
55
|
else
|
37
56
|
@app.call(env)
|
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.0.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|