napa-ext 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/napa/ext/swagger_doc.rb +40 -0
- data/lib/napa/ext/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51fa537664dece05e4b531864907c154f317e353
|
4
|
+
data.tar.gz: 7294b9ba02815b63f975f0fb72712a6a9bd5bf31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d078613aac1dfe53acb444b6a98210fec08b4d05e8abb2990edda49573272a53399fde5891be47202caab7f2771f0fa857c26cdfe58b05e80654000e7d45d314
|
7
|
+
data.tar.gz: 7b20e2416bcc225ba9768863fea92008657de64e0c2ce9a967c467fc524ce2c0effebeea963fdaf031df0a55b58d524d94d88d8ac64148ce8b6fba1c496dcf15
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Napa
|
2
|
+
module Ext
|
3
|
+
class SwaggerDoc
|
4
|
+
def initialize app, api_doc_path: '/api_doc'
|
5
|
+
@app = app
|
6
|
+
@api_doc_path = api_doc_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def call env
|
10
|
+
if enabled? && api_doc?(env)
|
11
|
+
[
|
12
|
+
'301',
|
13
|
+
{ 'Location' => target_swagger_url(env), 'Content-Type' => 'text/html' },
|
14
|
+
[]
|
15
|
+
]
|
16
|
+
else
|
17
|
+
app.call env
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :app, :api_doc_path
|
24
|
+
|
25
|
+
def api_doc? env
|
26
|
+
env['PATH_INFO'] == api_doc_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def enabled?
|
30
|
+
ENV.key? 'SWAGGER_UI_URL'
|
31
|
+
end
|
32
|
+
|
33
|
+
def target_swagger_url env
|
34
|
+
swagger_api_uri = env['REQUEST_URI'].gsub api_doc_path, '/swagger_doc'
|
35
|
+
|
36
|
+
"#{ENV['SWAGGER_UI_URL']}?swagger_doc=#{swagger_api_uri}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/napa/ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napa-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- soloman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- lib/napa/ext.rb
|
99
99
|
- lib/napa/ext/poison.rb
|
100
|
+
- lib/napa/ext/swagger_doc.rb
|
100
101
|
- lib/napa/ext/version.rb
|
101
102
|
- napa-ext.gemspec
|
102
103
|
homepage: ''
|
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
120
|
version: '0'
|
120
121
|
requirements: []
|
121
122
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.2.2
|
123
124
|
signing_key:
|
124
125
|
specification_version: 4
|
125
126
|
summary: Some additional Napa middlewares
|