swagui 0.0.5 → 0.0.6

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: bdf2575a9ae929db8fedb063d163fd16171acdc9
4
- data.tar.gz: 4d1c091e34f0b834fe2aaa1e26cadc66d51d3803
3
+ metadata.gz: 5ab94a4ed97c6df7d5274224ffcf4da84f6e1367
4
+ data.tar.gz: 4821b3413d845dbcb2d94cfd4450686cd0264d47
5
5
  SHA512:
6
- metadata.gz: bea3ee5134a6d4d8d4437715bc10cb343e3d56807bf316916fa4965a272fe53cc180a085804eb0d097641461283f019571f36ba49e5a155f231ce59b6ed50f3a
7
- data.tar.gz: f671a36ccf195e09260a8b9b7088ba6bbb2863d388979a9c23ab859e26d70c1b17f30079ba6b928e6f9b4c29f32883b8c7a827e41c11aa6ac5a4778b8bcbf47f
6
+ metadata.gz: 667c6bac6f78a29211d5d08827bc4563ad7a6afc7adbbd31065d77feb286c6728ceebaf7212e9f4693dfd20733df5772f6be9b711bb3991009053d7d9b26c943
7
+ data.tar.gz: 67bbada1aa02f87a3a7517b63555b1a522e94b23971fb8cbef142f688db358581cd4f983f2802630ba1cd609282346bde1e15794cbf196e4bf33fcd2d5f1f8e2
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Swigui
1
+ # Swagui
2
2
 
3
3
  a Rack middleware app and a command-line utility that helps you render [swagger-ui], a great api documentation tool, with ease and grace.
4
4
 
@@ -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
- env["PATH_INFO"] = path
34
- @app_file_server.call(env)
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)
@@ -1,3 +1,3 @@
1
1
  module Swagui
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
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.0.5
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-08-04 00:00:00.000000000 Z
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack