lazy_api_doc 0.1.2 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a399e710f96856c2fb1763fb625647a60b089096c58a42bfecdda84ed9c199a
4
- data.tar.gz: 842381548c69be6d6aea07a31aff8db2a26eb9c2b8e8c074390ae01a9a50b980
3
+ metadata.gz: 31368d253e80c44fce567ac28d48de2e4ade297e3b4801633d5a71d3256da89a
4
+ data.tar.gz: d1030d418b1a8097be35afc5a0d6bb86242da3e7b59e84f8fbdc49bac383fd34
5
5
  SHA512:
6
- metadata.gz: 49e6405242909d210c727775d862dbce8c6afddbb744ab69a037530bebbc72be88a4da83c44b2f8402b76f8eec7acee498710640ba694de479c1067b6834a40e
7
- data.tar.gz: 7e80fd689eaa7e7f3493d0e07d31d63229daa2b82b5a9039663358a19c7a58fa9432db2672c91ee19da062a12136f66a595d20d931d6278606e06b2c54623b31
6
+ metadata.gz: f223f1e4133df068b6587aa0e2cecdede3dec1c1f52e4af2946573927745aac3787fc98168ebeb149b3a2d2cef751179def7c345069abf2ce43d5f9b8b76c40d
7
+ data.tar.gz: 62281755d82ec9ac3de295d24bc108f4c462e5c08ebd8507690896dfae276acceffeff9768338ef536dc76d0907407e501c182e13b823414151c2c462961b4b7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.6.4
1
+ ruby-3.0.3
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lazy_api_doc (0.1.2)
4
+ lazy_api_doc (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.0)
10
10
  diff-lcs (1.3)
11
- docile (1.3.2)
11
+ docile (1.4.0)
12
12
  jaro_winkler (1.5.4)
13
13
  parallel (1.19.0)
14
14
  parser (2.6.5.0)
@@ -38,10 +38,12 @@ GEM
38
38
  rubocop-rspec (1.38.1)
39
39
  rubocop (>= 0.68.1)
40
40
  ruby-progressbar (1.10.1)
41
- simplecov (0.18.5)
41
+ simplecov (0.21.2)
42
42
  docile (~> 1.1)
43
43
  simplecov-html (~> 0.11)
44
- simplecov-html (0.12.2)
44
+ simplecov_json_formatter (~> 0.1)
45
+ simplecov-html (0.12.3)
46
+ simplecov_json_formatter (0.1.3)
45
47
  unicode-display_width (1.6.0)
46
48
 
47
49
  PLATFORMS
@@ -56,4 +58,4 @@ DEPENDENCIES
56
58
  simplecov
57
59
 
58
60
  BUNDLED WITH
59
- 2.1.2
61
+ 2.2.32
data/README.md CHANGED
@@ -45,6 +45,18 @@ The documentation will be placed `public/lazy_api_doc/api.yml`. To see it just r
45
45
 
46
46
  and navigate to http://localhost:3000/lazy_api_doc/
47
47
 
48
+ ## How does it work under the hood?
49
+
50
+ LazyApiDoc gathers your test requests and responses, group them by controllers and actions that were affected, and tries to guess the type of every field.
51
+ ```json
52
+ user: {
53
+ id: 1, // Integer
54
+ name: "John Doe", // String,
55
+ created_at: "2020-05-17 20:15:47Z -0400" // DateTime
56
+ }
57
+ ```
58
+ After that, it just builds an OpenAPI specification based on it.
59
+
48
60
  ## Contributing
49
61
 
50
62
  Bug reports and pull requests are welcome on GitHub at https://github.com/bguban/lazy_api_doc. This project is intended
@@ -3,8 +3,8 @@ module LazyApiDocInterceptor
3
3
 
4
4
  included do
5
5
  %w[get post patch put head delete].each do |method|
6
- define_method(method) do |*args|
7
- result = super(*args)
6
+ define_method(method) do |*args, **kwargs|
7
+ result = super(*args, **kwargs)
8
8
  # self.class.metadata[:doc]
9
9
  LazyApiDoc.add_test(self)
10
10
  result
@@ -3,8 +3,8 @@ module LazyApiDocInterceptor
3
3
 
4
4
  included do
5
5
  %w[get post patch put head delete].each do |method|
6
- define_method(method) do |*args|
7
- result = super(*args)
6
+ define_method(method) do |*args, **kwargs|
7
+ result = super(*args, **kwargs)
8
8
  # self.class.metadata[:doc] can be used to document only tests with doc: true metadata
9
9
  LazyApiDoc.add_spec(self)
10
10
  result
@@ -11,12 +11,13 @@ module LazyApiDoc
11
11
  def add(example)
12
12
  return if example[:controller] == "anonymous" # don't handle virtual controllers
13
13
 
14
- @examples << OpenStruct.new(example)
14
+ @examples << example
15
15
  end
16
16
 
17
17
  def result
18
18
  result = {}
19
- @examples.sort_by(&:source_location).group_by { |ex| [ex.controller, ex.action] }.map do |_, examples|
19
+ @examples.map { |example| OpenStruct.new(example) }.sort_by(&:source_location)
20
+ .group_by { |ex| [ex.controller, ex.action] }.map do |_, examples|
20
21
  first = examples.first
21
22
  route = ::LazyApiDoc::RouteParser.new(first.controller, first.action, first.verb).route
22
23
  doc_path = route[:doc_path]
@@ -28,7 +29,7 @@ module LazyApiDoc
28
29
 
29
30
  def example_group(example, examples, route) # rubocop:disable Metrics/AbcSize
30
31
  {
31
- route[:verb].downcase => {
32
+ example['verb'].downcase => {
32
33
  "tags" => [example.controller],
33
34
  "description" => example["description"].capitalize,
34
35
  "summary" => example.action,
@@ -95,9 +96,9 @@ module LazyApiDoc
95
96
  end
96
97
 
97
98
  def body_params(route, examples)
98
- return if route[:verb] == "GET"
99
-
100
99
  first = examples.first
100
+ return unless %w[POST PATCH].include?(first['verb'])
101
+
101
102
  variants = examples.map { |example| example.params.except("controller", "action", *route[:path_params]) }
102
103
  {
103
104
  'content' => {
@@ -15,34 +15,19 @@ module LazyApiDoc
15
15
  def self.routes
16
16
  return @routes if defined?(@routes)
17
17
 
18
- all_routes = Rails.application.routes.routes
19
- require "action_dispatch/routing/inspector"
20
- inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
21
- @routes = inspector.format(JsonRoutesFormatter.new, ENV["CONTROLLER"])
18
+ @routes = Rails.application.routes.routes.map { |route| format(route) }
22
19
  end
23
- end
24
- end
25
20
 
26
- class JsonRoutesFormatter
27
- def initialize
28
- @buffer = []
29
- end
21
+ def self.format(route)
22
+ route = ActionDispatch::Routing::RouteWrapper.new(route)
30
23
 
31
- def result
32
- @buffer
33
- end
34
-
35
- def section_title(_title); end
36
-
37
- def section(routes)
38
- @buffer = routes.map do |r|
39
- r[:doc_path] = r[:path].gsub("(.:format)", "").gsub(/(:\w+)/, '{\1}').delete(":")
40
- r[:path_params] = r[:path].gsub("(.:format)", "").scan(/:\w+/).map { |p| p.delete(":").to_sym }
41
- r[:controller] = r[:reqs].split("#").first
42
- r[:action] = r[:reqs].split("#").last.split(" ").first
43
- r
24
+ {
25
+ doc_path: route.path.gsub("(.:format)", "").gsub(/(:\w+)/, '{\1}').delete(":"),
26
+ path_params: route.path.gsub("(.:format)", "").scan(/:\w+/).map { |p| p.delete(":").to_sym },
27
+ controller: route.controller,
28
+ action: route.action,
29
+ verb: route.verb.split('|')
30
+ }
44
31
  end
45
32
  end
46
-
47
- def header(_routes); end
48
33
  end
@@ -83,7 +83,7 @@ module LazyApiDoc
83
83
  def parse_array(variant, variants)
84
84
  first = variant.first
85
85
  types_template(variants).merge(
86
- "items" => parse(first, variants.map(&:first).compact),
86
+ "items" => parse(first, variants.compact.map(&:first).compact),
87
87
  "example" => variant
88
88
  )
89
89
  end
@@ -1,3 +1,3 @@
1
1
  module LazyApiDoc
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.6".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.1.2
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Guban
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-10 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: The gem collects all requests and responses from your request specs and
14
14
  generates documentationbased on it
@@ -51,7 +51,7 @@ metadata:
51
51
  homepage_uri: https://github.com/bguban/lazy_api_doc
52
52
  source_code_uri: https://github.com/bguban/lazy_api_doc
53
53
  changelog_uri: https://github.com/bguban/lazy_api_doc
54
- post_install_message:
54
+ post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.0.6
70
- signing_key:
69
+ rubygems_version: 3.2.32
70
+ signing_key:
71
71
  specification_version: 4
72
72
  summary: Creates openapi v3 documentation based on rspec request tests
73
73
  test_files: []