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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af5749a17e1dece2e3ae5aeb8cc40d4452fc5ea09bd7574eb00e9110711a1c68
4
- data.tar.gz: e921f572e2fbb00a6553c9fa29bfb902b8eec16c9178dc82ccb8f7fc770cbd23
3
+ metadata.gz: ef3ed91d230146fe8a9ec8848a38faaa15b74bbe9543cce9bbf9df31378b2364
4
+ data.tar.gz: 9a8d617d8e7ee944da9fe0d3044b38a95bc9a030be816565f6efe686ff90c84b
5
5
  SHA512:
6
- metadata.gz: 01c31a46f50ecea8a0ae7b7fb27a6190640a4455e78cd0e703e61873b58bb77fdcb85206ea177b06b707ad79d2ef0191e7730c2e69d7ee2d3a056c69e2dcb9c1
7
- data.tar.gz: a3e2353321040cd4720c0de6d4f1109010e8511c5555a5d76d28a17a359d566ccbce0a027cae51ab47deb18ae4782847303386f45f286a35b74038d9a2a23cdc
6
+ metadata.gz: 6122f584b76193d5ce943208d67a8c3e80637acf3c78f78381629fc67b468ac337dc7ffb17cefcb1cefc7b4a18b2ab6a531113c3b138e99b2bc92c1a999d07bb
7
+ data.tar.gz: de1c56436fb2fca419cd0a2fa25a051cc08da77820dc4c9f8da9dfe5182d125275fc041254b721376b1432d0cb251fe6111c31c4a717a4391e924a84891c61c2
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  coverage
13
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lazy_api_doc (0.2.4)
4
+ lazy_api_doc (0.2.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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 { |ex| [ex.controller, ex.action] }
27
- .each do |_, examples|
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 DELETE HEAD].include?(example['verb'])
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
- attr_reader :controller, :action, :verb
4
-
5
- def initialize(controller, action, verb)
6
- @controller = controller
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
@@ -1,3 +1,3 @@
1
1
  module LazyApiDoc
2
- VERSION = "0.2.4".freeze
2
+ VERSION = "0.2.5".freeze
3
3
  end
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
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-03-30 00:00:00.000000000 Z
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