rpdoc 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +207 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/generators/rpdoc/install_generator.rb +16 -0
- data/lib/generators/templates/initializer.rb +43 -0
- data/lib/rpdoc/configuration.rb +52 -0
- data/lib/rpdoc/helper.rb +36 -0
- data/lib/rpdoc/postman_collection.rb +132 -0
- data/lib/rpdoc/postman_response.rb +91 -0
- data/lib/rpdoc/version.rb +5 -0
- data/lib/rpdoc.rb +23 -0
- data/rpdoc.gemspec +43 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 72d3497d62e6af176d18871c5cc1e375cfe8582fb7f450880b0ef84b90f5d302
|
4
|
+
data.tar.gz: db8a565df0f83ff24dd6d0a2f3f226dac63c17ddd20646f65d5b1dba80341a1a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 288aae7de390ecf88baa08a546d7c78d03460f2e80470a98bb26e762f6e9e2a0d8165e07f811b340cda006771a54272c78332804292a9c365145b5dad25320fc
|
7
|
+
data.tar.gz: 4589ba86931cbc983b7a3dea03a4d7bf74c5285b940fb7ab249352f59d559a1172f4733b44c5fbfd37c1fcc6aa53f7ca8e4d873bed0bc8a58c9078f1e22c4a95
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rpdoc (0.1.0)
|
5
|
+
json_requester (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (6.1.4.1)
|
11
|
+
actionpack (= 6.1.4.1)
|
12
|
+
activesupport (= 6.1.4.1)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (6.1.4.1)
|
16
|
+
actionpack (= 6.1.4.1)
|
17
|
+
activejob (= 6.1.4.1)
|
18
|
+
activerecord (= 6.1.4.1)
|
19
|
+
activestorage (= 6.1.4.1)
|
20
|
+
activesupport (= 6.1.4.1)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (6.1.4.1)
|
23
|
+
actionpack (= 6.1.4.1)
|
24
|
+
actionview (= 6.1.4.1)
|
25
|
+
activejob (= 6.1.4.1)
|
26
|
+
activesupport (= 6.1.4.1)
|
27
|
+
mail (~> 2.5, >= 2.5.4)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
actionpack (6.1.4.1)
|
30
|
+
actionview (= 6.1.4.1)
|
31
|
+
activesupport (= 6.1.4.1)
|
32
|
+
rack (~> 2.0, >= 2.0.9)
|
33
|
+
rack-test (>= 0.6.3)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (6.1.4.1)
|
37
|
+
actionpack (= 6.1.4.1)
|
38
|
+
activerecord (= 6.1.4.1)
|
39
|
+
activestorage (= 6.1.4.1)
|
40
|
+
activesupport (= 6.1.4.1)
|
41
|
+
nokogiri (>= 1.8.5)
|
42
|
+
actionview (6.1.4.1)
|
43
|
+
activesupport (= 6.1.4.1)
|
44
|
+
builder (~> 3.1)
|
45
|
+
erubi (~> 1.4)
|
46
|
+
rails-dom-testing (~> 2.0)
|
47
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
+
activejob (6.1.4.1)
|
49
|
+
activesupport (= 6.1.4.1)
|
50
|
+
globalid (>= 0.3.6)
|
51
|
+
activemodel (6.1.4.1)
|
52
|
+
activesupport (= 6.1.4.1)
|
53
|
+
activerecord (6.1.4.1)
|
54
|
+
activemodel (= 6.1.4.1)
|
55
|
+
activesupport (= 6.1.4.1)
|
56
|
+
activestorage (6.1.4.1)
|
57
|
+
actionpack (= 6.1.4.1)
|
58
|
+
activejob (= 6.1.4.1)
|
59
|
+
activerecord (= 6.1.4.1)
|
60
|
+
activesupport (= 6.1.4.1)
|
61
|
+
marcel (~> 1.0.0)
|
62
|
+
mini_mime (>= 1.1.0)
|
63
|
+
activesupport (6.1.4.1)
|
64
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
|
+
i18n (>= 1.6, < 2)
|
66
|
+
minitest (>= 5.1)
|
67
|
+
tzinfo (~> 2.0)
|
68
|
+
zeitwerk (~> 2.3)
|
69
|
+
ast (2.4.2)
|
70
|
+
builder (3.2.4)
|
71
|
+
coderay (1.1.3)
|
72
|
+
concurrent-ruby (1.1.9)
|
73
|
+
crass (1.0.6)
|
74
|
+
diff-lcs (1.4.4)
|
75
|
+
erubi (1.10.0)
|
76
|
+
faraday (1.8.0)
|
77
|
+
faraday-em_http (~> 1.0)
|
78
|
+
faraday-em_synchrony (~> 1.0)
|
79
|
+
faraday-excon (~> 1.1)
|
80
|
+
faraday-httpclient (~> 1.0.1)
|
81
|
+
faraday-net_http (~> 1.0)
|
82
|
+
faraday-net_http_persistent (~> 1.1)
|
83
|
+
faraday-patron (~> 1.0)
|
84
|
+
faraday-rack (~> 1.0)
|
85
|
+
multipart-post (>= 1.2, < 3)
|
86
|
+
ruby2_keywords (>= 0.0.4)
|
87
|
+
faraday-em_http (1.0.0)
|
88
|
+
faraday-em_synchrony (1.0.0)
|
89
|
+
faraday-excon (1.1.0)
|
90
|
+
faraday-httpclient (1.0.1)
|
91
|
+
faraday-net_http (1.0.1)
|
92
|
+
faraday-net_http_persistent (1.2.0)
|
93
|
+
faraday-patron (1.0.0)
|
94
|
+
faraday-rack (1.0.0)
|
95
|
+
globalid (0.5.2)
|
96
|
+
activesupport (>= 5.0)
|
97
|
+
i18n (1.8.10)
|
98
|
+
concurrent-ruby (~> 1.0)
|
99
|
+
json_requester (1.0.3)
|
100
|
+
faraday (>= 1.0.0)
|
101
|
+
loofah (2.12.0)
|
102
|
+
crass (~> 1.0.2)
|
103
|
+
nokogiri (>= 1.5.9)
|
104
|
+
mail (2.7.1)
|
105
|
+
mini_mime (>= 0.1.1)
|
106
|
+
marcel (1.0.2)
|
107
|
+
method_source (1.0.0)
|
108
|
+
mini_mime (1.1.2)
|
109
|
+
minitest (5.14.4)
|
110
|
+
multipart-post (2.1.1)
|
111
|
+
nio4r (2.5.8)
|
112
|
+
nokogiri (1.12.5-x86_64-darwin)
|
113
|
+
racc (~> 1.4)
|
114
|
+
parallel (1.21.0)
|
115
|
+
parser (3.0.2.0)
|
116
|
+
ast (~> 2.4.1)
|
117
|
+
pry (0.14.1)
|
118
|
+
coderay (~> 1.1)
|
119
|
+
method_source (~> 1.0)
|
120
|
+
racc (1.6.0)
|
121
|
+
rack (2.2.3)
|
122
|
+
rack-test (1.1.0)
|
123
|
+
rack (>= 1.0, < 3)
|
124
|
+
rails (6.1.4.1)
|
125
|
+
actioncable (= 6.1.4.1)
|
126
|
+
actionmailbox (= 6.1.4.1)
|
127
|
+
actionmailer (= 6.1.4.1)
|
128
|
+
actionpack (= 6.1.4.1)
|
129
|
+
actiontext (= 6.1.4.1)
|
130
|
+
actionview (= 6.1.4.1)
|
131
|
+
activejob (= 6.1.4.1)
|
132
|
+
activemodel (= 6.1.4.1)
|
133
|
+
activerecord (= 6.1.4.1)
|
134
|
+
activestorage (= 6.1.4.1)
|
135
|
+
activesupport (= 6.1.4.1)
|
136
|
+
bundler (>= 1.15.0)
|
137
|
+
railties (= 6.1.4.1)
|
138
|
+
sprockets-rails (>= 2.0.0)
|
139
|
+
rails-dom-testing (2.0.3)
|
140
|
+
activesupport (>= 4.2.0)
|
141
|
+
nokogiri (>= 1.6)
|
142
|
+
rails-html-sanitizer (1.4.2)
|
143
|
+
loofah (~> 2.3)
|
144
|
+
railties (6.1.4.1)
|
145
|
+
actionpack (= 6.1.4.1)
|
146
|
+
activesupport (= 6.1.4.1)
|
147
|
+
method_source
|
148
|
+
rake (>= 0.13)
|
149
|
+
thor (~> 1.0)
|
150
|
+
rainbow (3.0.0)
|
151
|
+
rake (13.0.6)
|
152
|
+
regexp_parser (2.1.1)
|
153
|
+
rexml (3.2.5)
|
154
|
+
rspec (3.10.0)
|
155
|
+
rspec-core (~> 3.10.0)
|
156
|
+
rspec-expectations (~> 3.10.0)
|
157
|
+
rspec-mocks (~> 3.10.0)
|
158
|
+
rspec-core (3.10.1)
|
159
|
+
rspec-support (~> 3.10.0)
|
160
|
+
rspec-expectations (3.10.1)
|
161
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
162
|
+
rspec-support (~> 3.10.0)
|
163
|
+
rspec-mocks (3.10.2)
|
164
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
165
|
+
rspec-support (~> 3.10.0)
|
166
|
+
rspec-support (3.10.2)
|
167
|
+
rubocop (1.22.3)
|
168
|
+
parallel (~> 1.10)
|
169
|
+
parser (>= 3.0.0.0)
|
170
|
+
rainbow (>= 2.2.2, < 4.0)
|
171
|
+
regexp_parser (>= 1.8, < 3.0)
|
172
|
+
rexml
|
173
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
174
|
+
ruby-progressbar (~> 1.7)
|
175
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
176
|
+
rubocop-ast (1.12.0)
|
177
|
+
parser (>= 3.0.1.1)
|
178
|
+
ruby-progressbar (1.11.0)
|
179
|
+
ruby2_keywords (0.0.5)
|
180
|
+
sprockets (4.0.2)
|
181
|
+
concurrent-ruby (~> 1.0)
|
182
|
+
rack (> 1, < 3)
|
183
|
+
sprockets-rails (3.2.2)
|
184
|
+
actionpack (>= 4.0)
|
185
|
+
activesupport (>= 4.0)
|
186
|
+
sprockets (>= 3.0.0)
|
187
|
+
thor (1.1.0)
|
188
|
+
tzinfo (2.0.4)
|
189
|
+
concurrent-ruby (~> 1.0)
|
190
|
+
unicode-display_width (2.1.0)
|
191
|
+
websocket-driver (0.7.5)
|
192
|
+
websocket-extensions (>= 0.1.0)
|
193
|
+
websocket-extensions (0.1.5)
|
194
|
+
zeitwerk (2.5.1)
|
195
|
+
|
196
|
+
PLATFORMS
|
197
|
+
x86_64-darwin-19
|
198
|
+
|
199
|
+
DEPENDENCIES
|
200
|
+
pry
|
201
|
+
rails (>= 5.0)
|
202
|
+
rpdoc!
|
203
|
+
rspec (~> 3.0)
|
204
|
+
rubocop (~> 1.0)
|
205
|
+
|
206
|
+
BUNDLED WITH
|
207
|
+
2.2.15
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 yuntai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Rpdoc
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rpdoc"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Rpdoc
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('../templates', __dir__)
|
9
|
+
desc 'Creates an initializer file at config/initializers.'
|
10
|
+
|
11
|
+
def copy_initializer_file
|
12
|
+
copy_file "initializer.rb", "#{Rails.root}/config/initializers/rpdoc.rb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rpdoc.configure do |config|
|
4
|
+
|
5
|
+
# (Optional) You can disable rpdoc generation process manually.
|
6
|
+
# config.rpdoc_enable = true
|
7
|
+
|
8
|
+
# (Optional) Apikey for your Postman account, used if need to push.
|
9
|
+
# config.postman_apikey = 'postman_apikey'
|
10
|
+
|
11
|
+
# (Optional) Workspace that your collection will be push to. Default your account's personal workspace.
|
12
|
+
# config.collection_workspace = 'collection_workspace'
|
13
|
+
|
14
|
+
# (Optional) Your existing collection uid. Will update it when using :push_and_update push strategy.
|
15
|
+
# config.collection_uid = 'collection_uid'
|
16
|
+
|
17
|
+
# (Optional) Collection name.
|
18
|
+
# config.collection_name = 'Rpdoc'
|
19
|
+
|
20
|
+
# (Optional) Your Rails server API host.
|
21
|
+
# config.rspec_server_host = '{{server_host}}'
|
22
|
+
|
23
|
+
# (Optional) Since Rspec generates many noisy headers, you can filter them.
|
24
|
+
# config.rspec_request_allow_headers = ['User-Agent', 'Content-Type', 'Authorization']
|
25
|
+
|
26
|
+
# (Optional) Folder that Rpdoc use for json data generation and save.
|
27
|
+
# config.rpdoc_root = 'rpdoc'
|
28
|
+
|
29
|
+
# (Optional) Filename to store RSpec request json data.
|
30
|
+
# config.rpdoc_request_filename = 'request.json'
|
31
|
+
|
32
|
+
# (Optional) Filename to store Postman description markdown data.
|
33
|
+
# config.rpdoc_description_filename = 'description.md'
|
34
|
+
|
35
|
+
# (Optional) Filename to store RSpec collection json data.
|
36
|
+
# config.rpdoc_collection_filename = 'collection.json'
|
37
|
+
|
38
|
+
# (Optional) Auto push collection to Postman server or not.
|
39
|
+
# config.rpdoc_auto_push = false
|
40
|
+
|
41
|
+
# (Optional) Auto push strategy, including :push_and_create and :push_and_update
|
42
|
+
# config.rpdoc_auto_push_strategy = :push_and_create
|
43
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rpdoc
|
4
|
+
class Configuration
|
5
|
+
attr_reader \
|
6
|
+
:postman_host,
|
7
|
+
:postman_collection_endpoint,
|
8
|
+
:collection_schema
|
9
|
+
|
10
|
+
attr_accessor \
|
11
|
+
:rpdoc_enable,
|
12
|
+
:postman_apikey,
|
13
|
+
:collection_workspace,
|
14
|
+
:collection_uid,
|
15
|
+
:collection_name,
|
16
|
+
:rspec_server_host,
|
17
|
+
:rspec_request_allow_headers,
|
18
|
+
:rpdoc_root,
|
19
|
+
:rpdoc_request_filename,
|
20
|
+
:rpdoc_description_filename,
|
21
|
+
:rpdoc_collection_filename,
|
22
|
+
:rpdoc_auto_push,
|
23
|
+
:rpdoc_auto_push_strategy
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@rpdoc_enable = true
|
27
|
+
|
28
|
+
@postman_host = 'https://api.getpostman.com'
|
29
|
+
@postman_collection_endpoint = "#{@postman_host}/collections"
|
30
|
+
@postman_apikey = nil
|
31
|
+
|
32
|
+
@collection_workspace = nil
|
33
|
+
@collection_uid = nil
|
34
|
+
@collection_name = 'Rpdoc'
|
35
|
+
@collection_schema = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
36
|
+
|
37
|
+
@rspec_server_host = '{{server_host}}'
|
38
|
+
@rspec_request_allow_headers = ['User-Agent', 'Content-Type', 'Authorization']
|
39
|
+
|
40
|
+
@rpdoc_root = 'rpdoc'
|
41
|
+
@rpdoc_request_filename = 'request.json'
|
42
|
+
@rpdoc_description_filename = 'description.md'
|
43
|
+
@rpdoc_collection_filename = 'collection.json'
|
44
|
+
@rpdoc_auto_push = false
|
45
|
+
@rpdoc_auto_push_strategy = :push_and_create # or :push_and_update
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid?
|
49
|
+
@rpdoc_enable && @rpdoc_auto_push ? !@postman_apikey.nil? : true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/rpdoc/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.before(:suite) do
|
5
|
+
if Rpdoc.configuration.rpdoc_enable
|
6
|
+
raise StandardError.new('Configuration Invalid') unless Rpdoc.configuration.valid?
|
7
|
+
Dir.glob("#{Rpdoc.configuration.rpdoc_root}/**/*.json") do |filename|
|
8
|
+
File.delete(filename)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
config.after(:suite) do
|
14
|
+
if Rpdoc.configuration.rpdoc_enable && Rpdoc.configuration.rpdoc_auto_push
|
15
|
+
postman_collection = Rpdoc::PostmanCollection.new
|
16
|
+
postman_collection.save
|
17
|
+
postman_collection.send(Rpdoc.configuration.rpdoc_auto_push_strategy)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.shared_context 'rpdoc' do
|
23
|
+
after(:each) do |example|
|
24
|
+
example.metadata[:rpdoc_skip] ||= false
|
25
|
+
if Rpdoc.configuration.rpdoc_enable && example.exception.nil? && example.metadata[:type] == :request && example.metadata[:rpdoc_skip] == false
|
26
|
+
example.metadata[:rpdoc_action_key] ||= controller.action_name
|
27
|
+
example.metadata[:rpdoc_action_name] ||= controller.action_name
|
28
|
+
example.metadata[:rpdoc_example_key] ||= example.metadata[:description].underscore
|
29
|
+
example.metadata[:rpdoc_example_name] ||= example.metadata[:description]
|
30
|
+
example.metadata[:rpdoc_example_folders] ||= controller.controller_path.split('/')
|
31
|
+
|
32
|
+
postman_response = Rpdoc::PostmanResponse.new(example, request, response)
|
33
|
+
postman_response.save
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rpdoc
|
4
|
+
class PostmanCollection
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@configuration = Rpdoc.configuration
|
8
|
+
@requester = JsonRequester.new(Settings.kdan_service.data_center)
|
9
|
+
|
10
|
+
@data = generated_collection_data
|
11
|
+
end
|
12
|
+
|
13
|
+
def push_and_create
|
14
|
+
path = "#{@configuration.postman_collection_endpoint}?workspace=#{@configuration.collection_workspace}"
|
15
|
+
headers = {
|
16
|
+
'X-Api-Key': @configuration.postman_apikey
|
17
|
+
}
|
18
|
+
@requester.http_send(:post, path, @data, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def push_and_update
|
22
|
+
path = "#{@configuration.postman_collection_endpoint}/#{@configuration.collection_uid}"
|
23
|
+
headers = {
|
24
|
+
'X-Api-Key': @configuration.postman_apikey
|
25
|
+
}
|
26
|
+
remote_collection_data = @requester.http_send(:get, path, {}, headers)
|
27
|
+
remote_collection_data = remote_collection_data['status'] == 200 ? remote_collection_data.deep_symbolize_keys.slice(:collection) : nil
|
28
|
+
|
29
|
+
merged_by(remote_collection_data)
|
30
|
+
@requester.http_send(:put, path, remote_collection_data, headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
def save
|
34
|
+
File.open("#{@configuration.rpdoc_root}/#{@configuration.rpdoc_collection_filename}", 'w+') do |f|
|
35
|
+
f.write(JSON.pretty_generate(@data))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def collection_data
|
42
|
+
@collection_data ||= @original_collection.present? ? @original_collection.deeper_merge(collection_from_rspec, merge_hash_arrays: true) : collection_from_rspec
|
43
|
+
end
|
44
|
+
|
45
|
+
def generated_collection_data
|
46
|
+
{
|
47
|
+
collection: {
|
48
|
+
info: {
|
49
|
+
name: @configuration.collection_name,
|
50
|
+
description: description(@configuration.rpdoc_root),
|
51
|
+
schema: @configuration.collection_schema
|
52
|
+
},
|
53
|
+
item: items(@configuration.rpdoc_root)
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def description(folder)
|
59
|
+
File.read("#{folder}/#{@configuration.rpdoc_description_filename}") rescue ""
|
60
|
+
end
|
61
|
+
|
62
|
+
def items(folder)
|
63
|
+
data = []
|
64
|
+
Dir.glob("#{folder}/*") do |filename|
|
65
|
+
next unless File.directory?(filename)
|
66
|
+
request_file = File.read("#{filename}/#{@configuration.rpdoc_request_filename}") rescue nil
|
67
|
+
request_data = JSON.parse(request_file).deep_symbolize_keys if request_file.present?
|
68
|
+
if request_data.present?
|
69
|
+
Dir.glob("#{filename}/*") do |response_filename|
|
70
|
+
next unless response_filename.match?(/.json$/) && response_filename != "#{filename}/#{@configuration.rpdoc_request_filename}"
|
71
|
+
response_data = JSON.parse(File.read(response_filename)).deep_symbolize_keys
|
72
|
+
request_data[:response] << response_data
|
73
|
+
end
|
74
|
+
request_data[:request][:description] = description(filename)
|
75
|
+
data << request_data
|
76
|
+
else
|
77
|
+
data << {
|
78
|
+
name: filename.split('/').last.camelize,
|
79
|
+
description: description(filename),
|
80
|
+
item: items(filename)
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
data
|
85
|
+
end
|
86
|
+
|
87
|
+
def merged_by(other_collection_data)
|
88
|
+
clean_generated_responses_from(other_collection_data[:collection][:item])
|
89
|
+
insert_generated_responses_into(other_collection_data[:collection][:item])
|
90
|
+
end
|
91
|
+
|
92
|
+
def clean_generated_responses_from(collection_items)
|
93
|
+
collection_items.each do |item|
|
94
|
+
if item.has_key?(:item)
|
95
|
+
clean_generated_responses_from(item[:item])
|
96
|
+
elsif item.has_key?(:response)
|
97
|
+
item[:response] = item[:response].reject do |response|
|
98
|
+
response.dig(:header)&.pluck(:key)&.include?('RSpec-Location')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def insert_generated_responses_into(collection_items, from_collection_items: nil)
|
105
|
+
from_collection_items ||= @data[:collection][:item]
|
106
|
+
|
107
|
+
if collection_items.empty?
|
108
|
+
collection_items = from_collection_items.deep_dup
|
109
|
+
else
|
110
|
+
item_hash = {}
|
111
|
+
collection_items.each do |item|
|
112
|
+
item_hash[item[:name]] = item
|
113
|
+
end
|
114
|
+
|
115
|
+
from_collection_items.each do |from_item|
|
116
|
+
from_item_name = from_item[:name]
|
117
|
+
if item_hash.has_key?(from_item_name)
|
118
|
+
if from_item.has_key?(:item) && item_hash[from_item_name].has_key?(:item)
|
119
|
+
insert_generated_responses_into(item_hash[from_item_name][:item], from_collection_items: from_item[:item])
|
120
|
+
elsif from_item.has_key?(:response) && item_hash[from_item_name].has_key?(:response)
|
121
|
+
item_hash[from_item_name][:response] += from_item[:response].deep_dup
|
122
|
+
else
|
123
|
+
collection_items << from_item.deep_dup
|
124
|
+
end
|
125
|
+
else
|
126
|
+
collection_items << from_item.deep_dup
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rpdoc
|
4
|
+
class PostmanResponse
|
5
|
+
attr_reader :data
|
6
|
+
|
7
|
+
def initialize(rspec_example, rspec_request, rspec_response)
|
8
|
+
@rspec_example = rspec_example
|
9
|
+
@rspec_request = rspec_request
|
10
|
+
@rspec_response = rspec_response
|
11
|
+
@configuration = Rpdoc.configuration
|
12
|
+
|
13
|
+
@data = response_data
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
root_path ||= @configuration.rpdoc_root
|
18
|
+
folder_path = "#{root_path}/#{@rspec_example.metadata[:rpdoc_example_folders].join('/')}/#{@rspec_example.metadata[:rpdoc_action_key]}"
|
19
|
+
FileUtils.mkdir_p(folder_path) unless File.exists?(folder_path)
|
20
|
+
|
21
|
+
request_file_path = "#{folder_path}/#{@configuration.rpdoc_request_filename}"
|
22
|
+
File.open(request_file_path, 'w+') { |f| f.write(JSON.pretty_generate(request_data)) } unless File.exists?(request_file_path)
|
23
|
+
|
24
|
+
response_file_path = "#{folder_path}/#{@rspec_example.metadata[:rpdoc_example_key]}.json"
|
25
|
+
File.open(response_file_path, 'w+') { |f| f.write(JSON.pretty_generate(response_data)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def request_data
|
31
|
+
{
|
32
|
+
name: @rspec_example.metadata[:rpdoc_action_name],
|
33
|
+
request: original_request_data,
|
34
|
+
response: []
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def response_data
|
39
|
+
headers = @rspec_response.header.map { |key, value| {key: key, value: value} }
|
40
|
+
headers << rspec_location_header
|
41
|
+
{
|
42
|
+
name: @rspec_example.metadata[:rpdoc_example_name],
|
43
|
+
originalRequest: original_request_data,
|
44
|
+
status: @rspec_response.status.to_s,
|
45
|
+
code: @rspec_response.code.to_i,
|
46
|
+
_postman_previewlanguage: "json",
|
47
|
+
header: headers,
|
48
|
+
body: JSON.pretty_generate(JSON.parse(@rspec_response.body))
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def rspec_location_header
|
53
|
+
{
|
54
|
+
key: 'RSpec-Location',
|
55
|
+
value: @rspec_example.metadata[:location]
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def original_request_data
|
60
|
+
return @original_request_data if @original_request_data.present?
|
61
|
+
filter_headers = @configuration.rspec_request_allow_headers.map do |header|
|
62
|
+
next unless @rspec_request.headers[header].present?
|
63
|
+
{
|
64
|
+
key: header,
|
65
|
+
value: @rspec_request.headers[header]
|
66
|
+
}
|
67
|
+
end.compact
|
68
|
+
@original_request_data = {
|
69
|
+
method: @rspec_request.method,
|
70
|
+
header: filter_headers,
|
71
|
+
url: {
|
72
|
+
raw: "#{@configuration.rspec_server_host}#{@rspec_request.path}",
|
73
|
+
host: [@configuration.rspec_server_host],
|
74
|
+
path: @rspec_request.path.split('/'),
|
75
|
+
variable: [],
|
76
|
+
},
|
77
|
+
body: nil
|
78
|
+
}
|
79
|
+
@original_request_data[:body] = {
|
80
|
+
mode: 'raw',
|
81
|
+
raw: JSON.pretty_generate(JSON.parse(@rspec_request.headers['RAW_POST_DATA'])),
|
82
|
+
options: {
|
83
|
+
raw: {
|
84
|
+
language: "json"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
} if @rspec_request.headers['RAW_POST_DATA'].present?
|
88
|
+
@original_request_data
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/rpdoc.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rpdoc/version'
|
4
|
+
require 'rpdoc/configuration'
|
5
|
+
require 'rpdoc/postman_response'
|
6
|
+
require 'rpdoc/postman_collection'
|
7
|
+
require 'rpdoc/helper' if defined?(RSpec)
|
8
|
+
|
9
|
+
module Rpdoc
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure(&block)
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/rpdoc.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rpdoc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rpdoc"
|
7
|
+
spec.version = Rpdoc::VERSION
|
8
|
+
spec.authors = ["yuntai"]
|
9
|
+
spec.email = ["yuntai.yang@kdanmobile.com"]
|
10
|
+
|
11
|
+
spec.summary = "A gem to transform RSpec examples to Postman collection"
|
12
|
+
spec.description = "With RSpec examples, it will generate Postman collection and push to the Postman server."
|
13
|
+
spec.homepage = "https://www.kdanmobile.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://www.kdanmobile.com"
|
21
|
+
spec.metadata["changelog_uri"] = "https://www.kdanmobile.com"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
spec.add_dependency 'json_requester', '~> 1.0'
|
35
|
+
|
36
|
+
spec.add_development_dependency 'rails', '>= 5.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'pry'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 1.0'
|
40
|
+
|
41
|
+
# For more information and examples about making a new gem, checkout our
|
42
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpdoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yuntai
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json_requester
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
description: With RSpec examples, it will generate Postman collection and push to
|
84
|
+
the Postman server.
|
85
|
+
email:
|
86
|
+
- yuntai.yang@kdanmobile.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/generators/rpdoc/install_generator.rb
|
102
|
+
- lib/generators/templates/initializer.rb
|
103
|
+
- lib/rpdoc.rb
|
104
|
+
- lib/rpdoc/configuration.rb
|
105
|
+
- lib/rpdoc/helper.rb
|
106
|
+
- lib/rpdoc/postman_collection.rb
|
107
|
+
- lib/rpdoc/postman_response.rb
|
108
|
+
- lib/rpdoc/version.rb
|
109
|
+
- rpdoc.gemspec
|
110
|
+
homepage: https://www.kdanmobile.com
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata:
|
114
|
+
homepage_uri: https://www.kdanmobile.com
|
115
|
+
source_code_uri: https://www.kdanmobile.com
|
116
|
+
changelog_uri: https://www.kdanmobile.com
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 2.4.0
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.2.15
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: A gem to transform RSpec examples to Postman collection
|
136
|
+
test_files: []
|