swagger_yard-rails 0.3.2 → 0.3.3
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/.ruby-version +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +5 -1
- data/lib/swagger_yard/rails/route_inspector.rb +28 -14
- data/lib/swagger_yard/rails/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 282e5f9bbc7d5b2c59bdfdf2240c48b70912bb6a
|
4
|
+
data.tar.gz: ed70441ac1bf98a36b0005bd0ace4bc622847b16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e605ac864174175af0a3c40a57720baae8a6d710756bb0faa6281112090ade40fc7351cc8e0cd94afe96616f6c4e8b515f7e4b32aec151095fd274a52b3164b8
|
7
|
+
data.tar.gz: e0745dcda80f5dc9dfbe04708d139d4efa7dc9f7f036873f62f9d39425b9b5a8be50560cda6c2baa7fa3edb89dd6756889d0dd7529c10e5496779ca256e5f028
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# SwaggerYard-Rails Changelog
|
2
2
|
|
3
|
+
## 0.3.3 25-07-2016 ##
|
4
|
+
|
5
|
+
* Descend into engine routes when searching for matches. This allows documented
|
6
|
+
APIs in engines to be included in the spec.
|
7
|
+
|
3
8
|
## 0.3.2 29-01-2016 ##
|
4
9
|
|
5
10
|
* Use `#controller_path` instead of duplicating controller name logic
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# SwaggerYard::Rails
|
2
2
|
|
3
|
+
[](http://travis-ci.org/livingsocial/swagger_yard-rails "Travis-CI swagger_yard-rails")
|
4
|
+
[](https://rubygems.org/gems/swagger_yard-rails)
|
5
|
+
|
6
|
+
|
3
7
|
The SwaggerYard::Rails gem is a Rails Engine designed to parse your Yardocs API controllers using SwaggerYard. It'll create a Swagger-UI complaint JSON to be served out through where you mount SwaggerYard::Rails::Engine.
|
4
8
|
|
5
9
|
## Installation
|
@@ -111,7 +115,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
111
115
|
|
112
116
|
## Contributing
|
113
117
|
|
114
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/livingsocial/swagger_yard-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
115
119
|
|
116
120
|
## License
|
117
121
|
|
@@ -16,15 +16,18 @@ module SwaggerYard
|
|
16
16
|
def call(yard_obj)
|
17
17
|
return nil if skip_object?(yard_obj)
|
18
18
|
|
19
|
-
info
|
20
|
-
|
21
|
-
|
19
|
+
info = yard_info(yard_obj)
|
20
|
+
route_arr = find_route(info)
|
21
|
+
route = route_arr.last
|
22
|
+
method = route.verb.source.gsub(/[$^]/, '')
|
22
23
|
|
23
24
|
raise Error, "no http method: #{info.inspect}" if method.empty?
|
24
25
|
|
25
|
-
path =
|
26
|
-
|
27
|
-
|
26
|
+
path = route_arr.map do |r|
|
27
|
+
r.parts.inject(r.ast.to_s) do |p,sym|
|
28
|
+
p.sub(sym.inspect, "{#{sym}}")
|
29
|
+
end
|
30
|
+
end.join
|
28
31
|
|
29
32
|
# FIXME: always remove format parameter?
|
30
33
|
path = path.sub('(.{format})', '')
|
@@ -59,20 +62,31 @@ module SwaggerYard
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def find_route(info)
|
62
|
-
matching_routes =
|
63
|
-
if info[:route]
|
64
|
-
r.name == info[:route]
|
65
|
-
else
|
66
|
-
r.defaults[:controller] == info[:controller] &&
|
67
|
-
r.defaults[:action] == info[:action]
|
68
|
-
end
|
69
|
-
end
|
65
|
+
matching_routes = walk_routes(info)
|
70
66
|
|
71
67
|
raise Error, "too many matches: #{info.inspect}" if matching_routes.size > 1
|
72
68
|
raise Error, "no matching route: #{info.inspect}" if matching_routes.size < 1
|
73
69
|
|
74
70
|
matching_routes.first
|
75
71
|
end
|
72
|
+
|
73
|
+
def walk_routes(info, routes = @routes, stack = [])
|
74
|
+
selected_routes = []
|
75
|
+
|
76
|
+
routes.each do |r|
|
77
|
+
if info[:route] && r.name == info[:route]
|
78
|
+
selected_routes << stack + [r]
|
79
|
+
elsif info[:controller] && info[:action] &&
|
80
|
+
r.defaults[:controller] == info[:controller] &&
|
81
|
+
r.defaults[:action] == info[:action]
|
82
|
+
selected_routes << stack + [r]
|
83
|
+
elsif r.app && r.app.respond_to?(:routes)
|
84
|
+
selected_routes += walk_routes(info, r.app.routes.set, stack + [r])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
selected_routes
|
89
|
+
end
|
76
90
|
end
|
77
91
|
end
|
78
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagger_yard-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -185,9 +185,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.4.
|
188
|
+
rubygems_version: 2.4.8
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Rails engine to parse and render json for Swagger UI
|
192
192
|
test_files: []
|
193
|
-
has_rdoc:
|