lazy_api_doc 0.2.0 → 0.2.3

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: 568bfda81852a9cd4823ac786f1bfe2de01a32dc42da6c192304c954dd2d731c
4
- data.tar.gz: 5d4ccbd550f9cf6b16f589b155e71f3dd120a3eb2a475aa43a7ef39e1b0f8bcf
3
+ metadata.gz: fa62cfe77df17307c22cb91c6a951e2820d1a4b5d9aa5abdcf2125048fe4442f
4
+ data.tar.gz: f9429c504ec51bd374877f5a6c2406cbd0ce03353b771136f1f3dc41877a5cb6
5
5
  SHA512:
6
- metadata.gz: 7a99bee831aba3c9e8781b413ed4d53c051b47624673296dfbbe94176ae5dd8e54b1130abd767d46e2ec88a473dfc0d813297a12c2f66a9a017ada45997e1091
7
- data.tar.gz: 8a05e6d6ea878f4eeba9c032a1b0533e83eafc497bd86b8a51a322b3b2f169059a3df2fb665ca9ff1c799c4df69a01d1a59d094c1d3c8ffd9985124842595770
6
+ metadata.gz: '08af3aec20c0c6f7b9281f51845411a9f3875aec62577a6b0eb2f7a185ea4a7c49ad95fbc87d3ae434850ced028b14f5de2f9816bfd12babd938790bc443e553'
7
+ data.tar.gz: a50c616f463aa585bb9afc963855e7149236a437fea129b225a204c3ee7687996d0e2d781821b358beb7473a97418fe8438f4a1eea09938dc36ba17b0cd5066f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lazy_api_doc (0.2.0)
4
+ lazy_api_doc (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -44,7 +44,7 @@ module LazyApiDoc
44
44
  # This peace of code handle using ParallelTests (tests runs in independent processes).
45
45
  # Just delete this block if you don't use ParallelTests
46
46
  if ENV['TEST_ENV_NUMBER'] && defined?(ParallelTests)
47
- LazyApiDoc.save_examples
47
+ LazyApiDoc.save_examples('rspec')
48
48
  ParallelTests.wait_for_other_processes_to_finish if ParallelTests.first_process?
49
49
  LazyApiDoc.load_examples
50
50
  end
@@ -75,7 +75,7 @@ module LazyApiDoc
75
75
  # This peace of code handle using ParallelTests (tests runs in independent processes).
76
76
  # Just delete this block if you don't use ParallelTests
77
77
  if ENV['TEST_ENV_NUMBER'] && defined?(ParallelTests)
78
- LazyApiDoc.save_examples
78
+ LazyApiDoc.save_examples('minitest')
79
79
  ParallelTests.wait_for_other_processes_to_finish if ParallelTests.first_process?
80
80
  LazyApiDoc.load_examples
81
81
  end
@@ -39,7 +39,7 @@ module LazyApiDoc
39
39
  def example_group(example, examples, route) # rubocop:disable Metrics/AbcSize
40
40
  {
41
41
  example['verb'].downcase => {
42
- "tags" => [example.controller],
42
+ "tags" => [example.controller || 'Ungrouped'],
43
43
  "description" => example["description"].capitalize,
44
44
  "summary" => example.action,
45
45
  "parameters" => path_params(route, examples) + query_params(examples),
@@ -85,12 +85,10 @@ module LazyApiDoc
85
85
 
86
86
  def query_params(examples)
87
87
  query_variants = examples.map do |example|
88
- full_path = example.request['full_path'].split('?')
89
- next {} if full_path.size == 1
88
+ _path, query = example.request['full_path'].split('?')
89
+ next {} unless query
90
90
 
91
- # TODO: simplify it
92
- full_path.last.split('&').map { |part| part.split('=').map { |each| CGI.unescape(each) } }.group_by(&:first)
93
- .transform_values { |v| v.map(&:last) }.map { |k, v| [k, k.match?(/\[\]\z/) ? v : v.first] }.to_h
91
+ CGI.parse(query).map { |k, v| [k.gsub('[]', ''), k.match?('\[\]') ? v : v.first] }.to_h
94
92
  end
95
93
 
96
94
  parsed = ::LazyApiDoc::VariantsParser.new(query_variants).result
@@ -73,10 +73,10 @@ module LazyApiDoc
73
73
  result["properties"] = variant.map do |key, val|
74
74
  [
75
75
  key.to_s,
76
- parse(val, variants.compact.map { |v| v.fetch(key, OPTIONAL) })
76
+ parse(val, variants.select { |v| v.is_a?(Hash) }.map { |v| v.fetch(key, OPTIONAL) })
77
77
  ]
78
78
  end.to_h
79
- result["required"] = variant.keys.select { |key| variants.compact.all? { |v| v.key?(key) } }
79
+ result["required"] = variant.keys.select { |key| variants.select { |v| v.is_a?(Hash) }.all? { |v| v.key?(key) } }
80
80
  result
81
81
  end
82
82
 
@@ -1,3 +1,3 @@
1
1
  module LazyApiDoc
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.3".freeze
3
3
  end
data/lib/lazy_api_doc.rb CHANGED
@@ -32,16 +32,16 @@ module LazyApiDoc
32
32
 
33
33
  def add_spec(rspec_example) # rubocop:disable Metrics/AbcSize
34
34
  add(
35
- 'controller' => rspec_example.request.params[:controller],
36
- 'action' => rspec_example.request.params[:action],
35
+ 'controller' => rspec_example.instance_variable_get(:@request).params[:controller],
36
+ 'action' => rspec_example.instance_variable_get(:@request).params[:action],
37
37
  'description' => rspec_example.class.description,
38
38
  'source_location' => [rspec_example.class.metadata[:file_path], rspec_example.class.metadata[:line_number]],
39
- 'verb' => rspec_example.request.method,
40
- 'params' => rspec_example.request.params,
41
- 'content_type' => rspec_example.request.content_type.to_s,
39
+ 'verb' => rspec_example.instance_variable_get(:@request).method,
40
+ 'params' => rspec_example.instance_variable_get(:@request).params,
41
+ 'content_type' => rspec_example.instance_variable_get(:@request).content_type.to_s,
42
42
  'request' => {
43
- 'query_params' => rspec_example.request.query_parameters,
44
- 'full_path' => rspec_example.request.fullpath
43
+ 'query_params' => rspec_example.instance_variable_get(:@request).query_parameters,
44
+ 'full_path' => rspec_example.instance_variable_get(:@request).fullpath
45
45
  },
46
46
  'response' => {
47
47
  'code' => rspec_example.response.status,
@@ -53,16 +53,16 @@ module LazyApiDoc
53
53
 
54
54
  def add_test(mini_test_example) # rubocop:disable Metrics/AbcSize
55
55
  add(
56
- 'controller' => mini_test_example.request.params[:controller],
57
- 'action' => mini_test_example.request.params[:action],
56
+ 'controller' => mini_test_example.instance_variable_get(:@request).params[:controller],
57
+ 'action' => mini_test_example.instance_variable_get(:@request).params[:action],
58
58
  'description' => mini_test_example.name.gsub(/\Atest_/, '').humanize,
59
59
  'source_location' => mini_test_example.method(mini_test_example.name).source_location,
60
- 'verb' => mini_test_example.request.method,
61
- 'params' => mini_test_example.request.params,
62
- 'content_type' => mini_test_example.request.content_type.to_s,
60
+ 'verb' => mini_test_example.instance_variable_get(:@request).method,
61
+ 'params' => mini_test_example.instance_variable_get(:@request).params,
62
+ 'content_type' => mini_test_example.instance_variable_get(:@request).content_type.to_s,
63
63
  'request' => {
64
- 'query_params' => mini_test_example.request.query_parameters,
65
- 'full_path' => mini_test_example.request.fullpath
64
+ 'query_params' => mini_test_example.instance_variable_get(:@request).query_parameters,
65
+ 'full_path' => mini_test_example.instance_variable_get(:@request).fullpath
66
66
  },
67
67
  'response' => {
68
68
  'code' => mini_test_example.response.status,
@@ -79,10 +79,10 @@ module LazyApiDoc
79
79
  File.write("#{path}/api.yml", layout.to_yaml)
80
80
  end
81
81
 
82
- def save_examples
82
+ def save_examples(process_name)
83
83
  FileUtils.mkdir("#{path}/examples") unless File.exist?("#{path}/examples")
84
84
  File.write(
85
- "#{path}/examples/rspec_#{ENV['TEST_ENV_NUMBER'] || SecureRandom.uuid}.json",
85
+ "#{path}/examples/#{process_name}_#{ENV['TEST_ENV_NUMBER'] || SecureRandom.uuid}.json",
86
86
  {
87
87
  created_at: Time.now.to_i,
88
88
  examples: generator.examples
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.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Guban
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-06 00:00:00.000000000 Z
11
+ date: 2022-06-04 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