rat_pack_swagger 0.4.0 → 0.4.1
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/lib/rat_pack_swagger/version.rb +1 -1
- data/lib/rat_pack_swagger.rb +12 -3
- data/lib/swagger_spec.rb +6 -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: 657d4dcce9e8fad06d8ea2dcd8e463f596b471aa
|
4
|
+
data.tar.gz: 7122d7893993c4da074f95c169cd582e41885a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c43d94e4c9af930241c8b09593aaf556c5f6001ae78909e307b5099228d804c85c7eb34ad1446503700eb00f7129babf5890559b85ebabda306f3aed6f657789
|
7
|
+
data.tar.gz: 61eb36988c1e184160d4c566f57baefc4e5018ab0826bd93493e17eb6499047a54838b12a9fa74a31ad6c0139bde62b8a5704d7af625ade5238a89ddb5145bfa
|
data/lib/rat_pack_swagger.rb
CHANGED
@@ -112,14 +112,21 @@ module Sinatra
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def tags(*args)
|
115
|
-
|
116
|
-
args.each{|a| t << a}
|
115
|
+
_spec.this_route.tags.concat(args)
|
117
116
|
end
|
118
117
|
|
119
118
|
def summary(s)
|
120
119
|
_spec.this_route.summary = s
|
121
120
|
end
|
122
121
|
|
122
|
+
def consumes(*args)
|
123
|
+
_spec.this_route.consumes.concat(args)
|
124
|
+
end
|
125
|
+
|
126
|
+
def produces(*args)
|
127
|
+
_spec.this_route.produces.concat(args)
|
128
|
+
end
|
129
|
+
|
123
130
|
def response(http_status_code, **kwargs, &block)
|
124
131
|
_spec.this_route.responses[http_status_code] = SwaggerObject.new(**kwargs, &block).to_h
|
125
132
|
end
|
@@ -138,7 +145,7 @@ module Sinatra
|
|
138
145
|
|
139
146
|
app.before do
|
140
147
|
@@validators ||= ::RatPackSwagger::RequestValidatorCollection.new
|
141
|
-
vs = @@validators.get(request.path, request.request_method.downcase)
|
148
|
+
vs = @@validators.get(request.path.gsub(/:(\w+)/, '{\1}'), request.request_method.downcase)
|
142
149
|
if vs && vs[:body]
|
143
150
|
request.body.rewind
|
144
151
|
vs[:body].validate(request.body.read)
|
@@ -151,7 +158,9 @@ module Sinatra
|
|
151
158
|
def self.route_added(verb, path, block)
|
152
159
|
return if path == '/v2/swagger.json'
|
153
160
|
verb.downcase!
|
161
|
+
path = path.gsub(/:(\w+)/, '{\1}')
|
154
162
|
return unless ['get', 'post', 'put', 'delete'].include?(verb)
|
163
|
+
return unless @@spec.this_route.swagger?
|
155
164
|
@@spec.register_this_route(path, verb)
|
156
165
|
|
157
166
|
parameters = @@spec.resolved_spec[:paths][path][verb][:parameters]
|
data/lib/swagger_spec.rb
CHANGED
@@ -28,11 +28,16 @@ module RatPackSwagger
|
|
28
28
|
def initialize
|
29
29
|
@tags = []
|
30
30
|
@consumes = []
|
31
|
+
@produces = []
|
31
32
|
@parameters = []
|
32
33
|
@responses = {}
|
33
34
|
@schemes = []
|
34
35
|
@security = []
|
35
36
|
end
|
37
|
+
|
38
|
+
def swagger?
|
39
|
+
to_h != {}
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
43
|
class SwaggerSpec
|
@@ -56,7 +61,7 @@ module RatPackSwagger
|
|
56
61
|
def route_consumes?(path, verb, mime)
|
57
62
|
route = @spec[:paths][path][verb]
|
58
63
|
return true if route[:consumes] && route[:consumes].include?(mime)
|
59
|
-
return true if @spec[:consumes].include?(mime)
|
64
|
+
return true if @spec[:consumes] && @spec[:consumes].include?(mime)
|
60
65
|
return false
|
61
66
|
end
|
62
67
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rat_pack_swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hildebrand
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json-schema
|