lazy_api_doc 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/lazy_api_doc/generator.rb +7 -8
- data/lib/lazy_api_doc/route_parser.rb +6 -12
- data/lib/lazy_api_doc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef3ed91d230146fe8a9ec8848a38faaa15b74bbe9543cce9bbf9df31378b2364
|
4
|
+
data.tar.gz: 9a8d617d8e7ee944da9fe0d3044b38a95bc9a030be816565f6efe686ff90c84b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6122f584b76193d5ce943208d67a8c3e80637acf3c78f78381629fc67b468ac337dc7ffb17cefcb1cefc7b4a18b2ab6a531113c3b138e99b2bc92c1a999d07bb
|
7
|
+
data.tar.gz: de1c56436fb2fca419cd0a2fa25a051cc08da77820dc4c9f8da9dfe5182d125275fc041254b721376b1432d0cb251fe6111c31c4a717a4391e924a84891c61c2
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -23,11 +23,10 @@ module LazyApiDoc
|
|
23
23
|
def result
|
24
24
|
result = {}
|
25
25
|
@examples.map { |example| OpenStruct.new(example) }.sort_by(&:source_location)
|
26
|
-
.group_by { |
|
27
|
-
.each do |
|
28
|
-
first = examples.first
|
29
|
-
route = ::LazyApiDoc::RouteParser.new(first.controller, first.action, first.verb).route
|
26
|
+
.group_by { |example| ::LazyApiDoc::RouteParser.find_by(example) }
|
27
|
+
.each do |route, examples|
|
30
28
|
next if route.nil? # TODO: think about adding such cases to log
|
29
|
+
first = examples.first
|
31
30
|
|
32
31
|
doc_path = route['doc_path']
|
33
32
|
result[doc_path] ||= {}
|
@@ -91,8 +90,8 @@ module LazyApiDoc
|
|
91
90
|
else
|
92
91
|
{}
|
93
92
|
end
|
94
|
-
if %w[GET
|
95
|
-
params.merge!(example.params.except(*EXCLUDED_PARAMS, *route['path_params']))
|
93
|
+
if %w[GET HEAD].include?(example['verb'])
|
94
|
+
params.merge!(example.params.except(*EXCLUDED_PARAMS, *route['path_params'], *route['defaults'].keys))
|
96
95
|
end
|
97
96
|
params
|
98
97
|
end
|
@@ -110,9 +109,9 @@ module LazyApiDoc
|
|
110
109
|
|
111
110
|
def body_params(route, examples)
|
112
111
|
first = examples.first
|
113
|
-
return unless %w[POST PATCH PUT].include?(first['verb'])
|
112
|
+
return unless %w[POST PATCH PUT DELETE].include?(first['verb'])
|
114
113
|
|
115
|
-
variants = examples.map { |example| example.params.except(*EXCLUDED_PARAMS, *route['path_params']) }
|
114
|
+
variants = examples.map { |example| example.params.except(*EXCLUDED_PARAMS, *route['path_params'], *route['defaults'].keys) }
|
116
115
|
{
|
117
116
|
'content' => {
|
118
117
|
first.content_type => {
|
@@ -1,15 +1,9 @@
|
|
1
1
|
module LazyApiDoc
|
2
2
|
class RouteParser
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@action = action
|
8
|
-
@verb = verb
|
9
|
-
end
|
10
|
-
|
11
|
-
def route
|
12
|
-
self.class.routes.find { |r| r['action'] == action && r['controller'] == controller && r['verb'].include?(verb) }
|
3
|
+
def self.find_by(example)
|
4
|
+
r = routes.find do |r|
|
5
|
+
r['verb'].include?(example.verb) && example.params.slice(*r['defaults'].keys) == r['defaults']
|
6
|
+
end
|
13
7
|
end
|
14
8
|
|
15
9
|
def self.routes
|
@@ -20,13 +14,13 @@ module LazyApiDoc
|
|
20
14
|
|
21
15
|
def self.format(route)
|
22
16
|
route = ActionDispatch::Routing::RouteWrapper.new(route)
|
23
|
-
|
24
17
|
{
|
25
18
|
'doc_path' => route.path.gsub("(.:format)", "").gsub(/(:\w+)/, '{\1}').delete(":"),
|
26
19
|
'path_params' => route.path.gsub("(.:format)", "").scan(/:\w+/).map { |p| p.delete(":") },
|
27
20
|
'controller' => route.controller,
|
28
21
|
'action' => route.action,
|
29
|
-
'verb' => route.verb.split('|')
|
22
|
+
'verb' => route.verb.split('|'),
|
23
|
+
'defaults' => route.defaults.transform_keys(&:to_s)
|
30
24
|
}
|
31
25
|
end
|
32
26
|
end
|
data/lib/lazy_api_doc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_api_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Guban
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'The gem collects all requests and responses from your request specs
|
14
14
|
and generates documentation based on it
|