lazy_api_doc 0.2.4 → 0.2.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 +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +47 -36
- data/docs/example/index.html +1 -1
- data/lazy_api_doc.gemspec +2 -0
- data/lib/generators/lazy_api_doc/templates/public/index.html +1 -1
- data/lib/lazy_api_doc/generator.rb +11 -8
- data/lib/lazy_api_doc/route_parser.rb +6 -12
- data/lib/lazy_api_doc/variants_parser.rb +4 -4
- data/lib/lazy_api_doc/version.rb +1 -1
- metadata +18 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3089fde7c5d3c9cce883fe8d92e2a945b35971e70d6ab7cdd6271dfd517ba642
|
|
4
|
+
data.tar.gz: 68b995f02c1057ae7bdc07eaf933640655804a947f49033b61e583e7f1e49ef8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9902d226187a5f4c2f3680f3585684adc7ca928dd6bd60b2971b71a901d7e27a874628a49b7c532cdf0d1f2bd8fb12f4d82119b5a7abb1adc65c4fe46e4bc819
|
|
7
|
+
data.tar.gz: 45d352415cdb5b57e7f21d6dba8d8c3275a8b7c3e305fb7029564ab54726c7f360d1483d6f38119b4af8badaf5d8a971162d3e513b0bf6a490c9987b09c7b30e
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.
|
|
1
|
+
ruby-3.4.4
|
data/Gemfile.lock
CHANGED
|
@@ -1,57 +1,68 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lazy_api_doc (0.2.
|
|
4
|
+
lazy_api_doc (0.2.6)
|
|
5
|
+
ostruct
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
9
|
specs:
|
|
9
|
-
ast (2.4.
|
|
10
|
-
diff-lcs (1.
|
|
11
|
-
docile (1.4.
|
|
12
|
-
json (2.
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
ast (2.4.3)
|
|
11
|
+
diff-lcs (1.6.2)
|
|
12
|
+
docile (1.4.1)
|
|
13
|
+
json (2.19.5)
|
|
14
|
+
language_server-protocol (3.17.0.5)
|
|
15
|
+
lint_roller (1.1.0)
|
|
16
|
+
ostruct (0.6.3)
|
|
17
|
+
parallel (1.28.0)
|
|
18
|
+
parser (3.3.11.1)
|
|
15
19
|
ast (~> 2.4.1)
|
|
20
|
+
racc
|
|
21
|
+
prism (1.9.0)
|
|
22
|
+
racc (1.8.1)
|
|
16
23
|
rainbow (3.1.1)
|
|
17
24
|
rake (12.3.3)
|
|
18
|
-
regexp_parser (2.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
rspec-
|
|
22
|
-
rspec-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rspec-expectations (3.9.0)
|
|
25
|
+
regexp_parser (2.12.0)
|
|
26
|
+
rspec (3.13.2)
|
|
27
|
+
rspec-core (~> 3.13.0)
|
|
28
|
+
rspec-expectations (~> 3.13.0)
|
|
29
|
+
rspec-mocks (~> 3.13.0)
|
|
30
|
+
rspec-core (3.13.6)
|
|
31
|
+
rspec-support (~> 3.13.0)
|
|
32
|
+
rspec-expectations (3.13.5)
|
|
27
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
28
|
-
rspec-support (~> 3.
|
|
29
|
-
rspec-mocks (3.
|
|
34
|
+
rspec-support (~> 3.13.0)
|
|
35
|
+
rspec-mocks (3.13.8)
|
|
30
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
-
rspec-support (~> 3.
|
|
32
|
-
rspec-support (3.
|
|
33
|
-
rubocop (1.
|
|
37
|
+
rspec-support (~> 3.13.0)
|
|
38
|
+
rspec-support (3.13.7)
|
|
39
|
+
rubocop (1.86.1)
|
|
34
40
|
json (~> 2.3)
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
language_server-protocol (~> 3.17.0.2)
|
|
42
|
+
lint_roller (~> 1.1.0)
|
|
43
|
+
parallel (>= 1.10)
|
|
44
|
+
parser (>= 3.3.0.2)
|
|
37
45
|
rainbow (>= 2.2.2, < 4.0)
|
|
38
|
-
regexp_parser (>=
|
|
39
|
-
|
|
40
|
-
rubocop-ast (>= 1.26.0, < 2.0)
|
|
46
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
47
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
41
48
|
ruby-progressbar (~> 1.7)
|
|
42
|
-
unicode-display_width (>= 2.4.0, <
|
|
43
|
-
rubocop-ast (1.
|
|
44
|
-
parser (>= 3.
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
50
|
+
rubocop-ast (1.49.1)
|
|
51
|
+
parser (>= 3.3.7.2)
|
|
52
|
+
prism (~> 1.7)
|
|
53
|
+
rubocop-rspec (3.9.0)
|
|
54
|
+
lint_roller (~> 1.1)
|
|
55
|
+
rubocop (~> 1.81)
|
|
47
56
|
ruby-progressbar (1.13.0)
|
|
48
|
-
simplecov (0.
|
|
57
|
+
simplecov (0.22.0)
|
|
49
58
|
docile (~> 1.1)
|
|
50
59
|
simplecov-html (~> 0.11)
|
|
51
60
|
simplecov_json_formatter (~> 0.1)
|
|
52
|
-
simplecov-html (0.
|
|
53
|
-
simplecov_json_formatter (0.1.
|
|
54
|
-
unicode-display_width (2.
|
|
61
|
+
simplecov-html (0.13.2)
|
|
62
|
+
simplecov_json_formatter (0.1.4)
|
|
63
|
+
unicode-display_width (3.2.0)
|
|
64
|
+
unicode-emoji (~> 4.1)
|
|
65
|
+
unicode-emoji (4.2.0)
|
|
55
66
|
|
|
56
67
|
PLATFORMS
|
|
57
68
|
ruby
|
|
@@ -65,4 +76,4 @@ DEPENDENCIES
|
|
|
65
76
|
simplecov
|
|
66
77
|
|
|
67
78
|
BUNDLED WITH
|
|
68
|
-
|
|
79
|
+
4.0.11
|
data/docs/example/index.html
CHANGED
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
21
21
|
<redoc spec-url='./api.yml'></redoc>
|
|
22
|
-
<script src="https://cdn.
|
|
22
|
+
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
|
|
23
23
|
</body>
|
|
24
24
|
</html>
|
data/lazy_api_doc.gemspec
CHANGED
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
21
21
|
<redoc spec-url='./api.yml'></redoc>
|
|
22
|
-
<script src="https://cdn.
|
|
22
|
+
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
|
|
23
23
|
</body>
|
|
24
24
|
</html>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'cgi'
|
|
2
|
+
require 'ostruct'
|
|
2
3
|
|
|
3
4
|
module LazyApiDoc
|
|
4
5
|
class Generator
|
|
@@ -23,12 +24,12 @@ module LazyApiDoc
|
|
|
23
24
|
def result
|
|
24
25
|
result = {}
|
|
25
26
|
@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
|
|
27
|
+
.group_by { |example| ::LazyApiDoc::RouteParser.find_by(example) }
|
|
28
|
+
.each do |route, examples|
|
|
30
29
|
next if route.nil? # TODO: think about adding such cases to log
|
|
31
30
|
|
|
31
|
+
first = examples.first
|
|
32
|
+
|
|
32
33
|
doc_path = route['doc_path']
|
|
33
34
|
result[doc_path] ||= {}
|
|
34
35
|
result[doc_path].merge!(example_group(first, examples, route))
|
|
@@ -91,8 +92,8 @@ module LazyApiDoc
|
|
|
91
92
|
else
|
|
92
93
|
{}
|
|
93
94
|
end
|
|
94
|
-
if %w[GET
|
|
95
|
-
params.merge!(example.params.except(*EXCLUDED_PARAMS, *route['path_params']))
|
|
95
|
+
if %w[GET HEAD].include?(example['verb'])
|
|
96
|
+
params.merge!(example.params.except(*EXCLUDED_PARAMS, *route['path_params'], *route['defaults'].keys))
|
|
96
97
|
end
|
|
97
98
|
params
|
|
98
99
|
end
|
|
@@ -110,9 +111,11 @@ module LazyApiDoc
|
|
|
110
111
|
|
|
111
112
|
def body_params(route, examples)
|
|
112
113
|
first = examples.first
|
|
113
|
-
return unless %w[POST PATCH PUT].include?(first['verb'])
|
|
114
|
+
return unless %w[POST PATCH PUT DELETE].include?(first['verb'])
|
|
114
115
|
|
|
115
|
-
variants = examples.map
|
|
116
|
+
variants = examples.map do |example|
|
|
117
|
+
example.params.except(*EXCLUDED_PARAMS, *route['path_params'], *route['defaults'].keys)
|
|
118
|
+
end
|
|
116
119
|
{
|
|
117
120
|
'content' => {
|
|
118
121
|
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
|
+
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
|
|
@@ -26,7 +26,7 @@ module LazyApiDoc
|
|
|
26
26
|
|
|
27
27
|
def types_template(variants)
|
|
28
28
|
types = types_of(variants)
|
|
29
|
-
if types.
|
|
29
|
+
if types.one?
|
|
30
30
|
{
|
|
31
31
|
"type" => types.first
|
|
32
32
|
}
|
|
@@ -69,15 +69,15 @@ module LazyApiDoc
|
|
|
69
69
|
|
|
70
70
|
def parse_hash(variants)
|
|
71
71
|
result = types_template(variants)
|
|
72
|
-
variant = variants.
|
|
72
|
+
variant = variants.grep(Hash).reverse_each
|
|
73
73
|
.with_object({}) { |v, res| res.merge!(v) }
|
|
74
74
|
result["properties"] = variant.to_h do |key, val|
|
|
75
75
|
[
|
|
76
76
|
key.to_s,
|
|
77
|
-
parse(val, variants.
|
|
77
|
+
parse(val, variants.grep(Hash).map { |v| v.fetch(key, OPTIONAL) })
|
|
78
78
|
]
|
|
79
79
|
end
|
|
80
|
-
result["required"] = variant.keys.select { |key| variants.
|
|
80
|
+
result["required"] = variant.keys.select { |key| variants.grep(Hash).all? { |v| v.key?(key) } }
|
|
81
81
|
result
|
|
82
82
|
end
|
|
83
83
|
|
data/lib/lazy_api_doc/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
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.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bogdan Guban
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ostruct
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
13
26
|
description: 'The gem collects all requests and responses from your request specs
|
|
14
27
|
and generates documentation based on it
|
|
15
28
|
|
|
@@ -58,7 +71,6 @@ metadata:
|
|
|
58
71
|
source_code_uri: https://github.com/bguban/lazy_api_doc
|
|
59
72
|
changelog_uri: https://github.com/bguban/lazy_api_doc
|
|
60
73
|
rubygems_mfa_required: 'true'
|
|
61
|
-
post_install_message:
|
|
62
74
|
rdoc_options: []
|
|
63
75
|
require_paths:
|
|
64
76
|
- lib
|
|
@@ -73,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
85
|
- !ruby/object:Gem::Version
|
|
74
86
|
version: '0'
|
|
75
87
|
requirements: []
|
|
76
|
-
rubygems_version: 3.
|
|
77
|
-
signing_key:
|
|
88
|
+
rubygems_version: 3.6.7
|
|
78
89
|
specification_version: 4
|
|
79
90
|
summary: Creates openapi v3 documentation based on rspec request tests
|
|
80
91
|
test_files: []
|