rpdoc 0.1.15 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +4 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +87 -58
- data/README.md +20 -6
- data/Rakefile +4 -1
- data/VERSION.md +1 -1
- data/lib/generators/templates/initializer.rb +14 -2
- data/lib/rpdoc/configuration.rb +16 -1
- data/lib/rpdoc/helper.rb +8 -2
- data/lib/rpdoc/postman_collection.rb +56 -21
- data/lib/rpdoc/postman_response.rb +6 -4
- data/lib/rpdoc/railtie.rb +14 -0
- data/lib/rpdoc/rpdoc.rake +5 -1
- data/lib/rpdoc/version.rb +1 -1
- data/lib/rpdoc.rb +2 -0
- data/rpdoc.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 963515874d698d5e0dc7a13f81ac47cfb669022c84e91561cab91c0a23963774
|
4
|
+
data.tar.gz: ac8543e04985d09166790d1f4604478995788cd10a5f38d95ba8b9e1637e6599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ca60eac1301f3aa5d320effbbb1065ed0a78374fc897793841ade037abce37a5d45ae6ae74bdbf4e94b222a2fb8d70cedfaa9fc4078a5cda646ee285d7ef8d9
|
7
|
+
data.tar.gz: be9d0823c2ff93d0709b523534e9705fcd0ad5048cc4af92fc05f9f096d5cec36300bce1b3c8087fe06845e166efef6c2a996c5936dc591ba13e5e63e9b7f204
|
data/.gitlab-ci.yml
CHANGED
@@ -5,6 +5,8 @@ stages:
|
|
5
5
|
rspec:
|
6
6
|
stage: rspec
|
7
7
|
image: ruby:3.2.1
|
8
|
+
tags:
|
9
|
+
- arm64
|
8
10
|
script:
|
9
11
|
- bundle install
|
10
12
|
- RPDOC_ENABLE=false rspec spec -fd
|
@@ -14,6 +16,8 @@ rspec:
|
|
14
16
|
to_gem:
|
15
17
|
stage: publish
|
16
18
|
image: ruby:3.2.1
|
19
|
+
tags:
|
20
|
+
- arm64
|
17
21
|
script:
|
18
22
|
- mkdir -p ~/.gem
|
19
23
|
- touch ~/.gem/credentials
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.2.0] - 2024-04-02
|
2
|
+
- Add `rspec_root`, `rspec_response_allow_headers`, and `rspec_response_identifier` options to configuration.
|
3
|
+
- Add public method `merge!` for PostmanCollection.
|
4
|
+
- Fix rake usage.
|
5
|
+
- Refactor.
|
6
|
+
|
7
|
+
## [0.1.16] - 2023-06-01
|
8
|
+
- Fix default rpdoc_example_folders bug.
|
9
|
+
|
1
10
|
## [0.1.15] - 2023-05-18
|
2
11
|
- Add gitlab templates.
|
3
12
|
- Update gemspec.
|
data/Gemfile.lock
CHANGED
@@ -1,116 +1,145 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rpdoc (0.
|
4
|
+
rpdoc (0.2.0)
|
5
|
+
activesupport (~> 6.1)
|
5
6
|
json_requester (~> 1.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
actionpack (6.1.7)
|
11
|
-
actionview (= 6.1.7)
|
12
|
-
activesupport (= 6.1.7)
|
11
|
+
actionpack (6.1.7.6)
|
12
|
+
actionview (= 6.1.7.6)
|
13
|
+
activesupport (= 6.1.7.6)
|
13
14
|
rack (~> 2.0, >= 2.0.9)
|
14
15
|
rack-test (>= 0.6.3)
|
15
16
|
rails-dom-testing (~> 2.0)
|
16
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
-
actionview (6.1.7)
|
18
|
-
activesupport (= 6.1.7)
|
18
|
+
actionview (6.1.7.6)
|
19
|
+
activesupport (= 6.1.7.6)
|
19
20
|
builder (~> 3.1)
|
20
21
|
erubi (~> 1.4)
|
21
22
|
rails-dom-testing (~> 2.0)
|
22
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
-
activesupport (6.1.7)
|
24
|
+
activesupport (6.1.7.6)
|
24
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
26
|
i18n (>= 1.6, < 2)
|
26
27
|
minitest (>= 5.1)
|
27
28
|
tzinfo (~> 2.0)
|
28
29
|
zeitwerk (~> 2.3)
|
29
30
|
ast (2.4.2)
|
31
|
+
base64 (0.1.1)
|
30
32
|
builder (3.2.4)
|
31
33
|
coderay (1.1.3)
|
32
|
-
concurrent-ruby (1.
|
34
|
+
concurrent-ruby (1.2.2)
|
33
35
|
crass (1.0.6)
|
34
36
|
diff-lcs (1.5.0)
|
35
|
-
erubi (1.
|
36
|
-
faraday (
|
37
|
-
faraday-
|
37
|
+
erubi (1.12.0)
|
38
|
+
faraday (1.10.3)
|
39
|
+
faraday-em_http (~> 1.0)
|
40
|
+
faraday-em_synchrony (~> 1.0)
|
41
|
+
faraday-excon (~> 1.1)
|
42
|
+
faraday-httpclient (~> 1.0)
|
43
|
+
faraday-multipart (~> 1.0)
|
44
|
+
faraday-net_http (~> 1.0)
|
45
|
+
faraday-net_http_persistent (~> 1.0)
|
46
|
+
faraday-patron (~> 1.0)
|
47
|
+
faraday-rack (~> 1.0)
|
48
|
+
faraday-retry (~> 1.0)
|
38
49
|
ruby2_keywords (>= 0.0.4)
|
39
|
-
faraday-
|
40
|
-
|
50
|
+
faraday-em_http (1.0.0)
|
51
|
+
faraday-em_synchrony (1.0.0)
|
52
|
+
faraday-excon (1.1.0)
|
53
|
+
faraday-httpclient (1.0.1)
|
54
|
+
faraday-multipart (1.0.4)
|
55
|
+
multipart-post (~> 2)
|
56
|
+
faraday-net_http (1.0.1)
|
57
|
+
faraday-net_http_persistent (1.2.0)
|
58
|
+
faraday-patron (1.0.0)
|
59
|
+
faraday-rack (1.0.0)
|
60
|
+
faraday-retry (1.0.3)
|
61
|
+
i18n (1.14.1)
|
41
62
|
concurrent-ruby (~> 1.0)
|
42
|
-
json (2.6.
|
43
|
-
json_requester (1.0
|
44
|
-
faraday (>= 1.0.0)
|
45
|
-
|
63
|
+
json (2.6.3)
|
64
|
+
json_requester (1.1.0)
|
65
|
+
faraday (~> 1.0, >= 1.0.0)
|
66
|
+
language_server-protocol (3.17.0.3)
|
67
|
+
loofah (2.21.3)
|
46
68
|
crass (~> 1.0.2)
|
47
|
-
nokogiri (>= 1.
|
69
|
+
nokogiri (>= 1.12.0)
|
48
70
|
method_source (1.0.0)
|
49
|
-
minitest (5.
|
50
|
-
|
71
|
+
minitest (5.19.0)
|
72
|
+
multipart-post (2.4.0)
|
73
|
+
nokogiri (1.15.4-arm64-darwin)
|
51
74
|
racc (~> 1.4)
|
52
|
-
nokogiri (1.
|
75
|
+
nokogiri (1.15.4-x86_64-darwin)
|
53
76
|
racc (~> 1.4)
|
54
|
-
parallel (1.
|
55
|
-
parser (3.
|
77
|
+
parallel (1.23.0)
|
78
|
+
parser (3.2.2.3)
|
56
79
|
ast (~> 2.4.1)
|
57
|
-
|
80
|
+
racc
|
81
|
+
pry (0.14.2)
|
58
82
|
coderay (~> 1.1)
|
59
83
|
method_source (~> 1.0)
|
60
|
-
racc (1.
|
61
|
-
rack (2.2.
|
62
|
-
rack-test (2.0
|
84
|
+
racc (1.7.1)
|
85
|
+
rack (2.2.8)
|
86
|
+
rack-test (2.1.0)
|
63
87
|
rack (>= 1.3)
|
64
|
-
rails-dom-testing (2.0
|
65
|
-
activesupport (>=
|
88
|
+
rails-dom-testing (2.2.0)
|
89
|
+
activesupport (>= 5.0.0)
|
90
|
+
minitest
|
66
91
|
nokogiri (>= 1.6)
|
67
|
-
rails-html-sanitizer (1.
|
68
|
-
loofah (~> 2.
|
69
|
-
|
70
|
-
|
71
|
-
|
92
|
+
rails-html-sanitizer (1.6.0)
|
93
|
+
loofah (~> 2.21)
|
94
|
+
nokogiri (~> 1.14)
|
95
|
+
railties (6.1.7.6)
|
96
|
+
actionpack (= 6.1.7.6)
|
97
|
+
activesupport (= 6.1.7.6)
|
72
98
|
method_source
|
73
99
|
rake (>= 12.2)
|
74
100
|
thor (~> 1.0)
|
75
101
|
rainbow (3.1.1)
|
76
102
|
rake (13.0.6)
|
77
|
-
regexp_parser (2.
|
78
|
-
rexml (3.2.
|
79
|
-
rspec (3.
|
80
|
-
rspec-core (~> 3.
|
81
|
-
rspec-expectations (~> 3.
|
82
|
-
rspec-mocks (~> 3.
|
83
|
-
rspec-core (3.
|
84
|
-
rspec-support (~> 3.
|
85
|
-
rspec-expectations (3.
|
103
|
+
regexp_parser (2.8.1)
|
104
|
+
rexml (3.2.6)
|
105
|
+
rspec (3.12.0)
|
106
|
+
rspec-core (~> 3.12.0)
|
107
|
+
rspec-expectations (~> 3.12.0)
|
108
|
+
rspec-mocks (~> 3.12.0)
|
109
|
+
rspec-core (3.12.2)
|
110
|
+
rspec-support (~> 3.12.0)
|
111
|
+
rspec-expectations (3.12.3)
|
86
112
|
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
-
rspec-support (~> 3.
|
88
|
-
rspec-mocks (3.
|
113
|
+
rspec-support (~> 3.12.0)
|
114
|
+
rspec-mocks (3.12.6)
|
89
115
|
diff-lcs (>= 1.2.0, < 2.0)
|
90
|
-
rspec-support (~> 3.
|
91
|
-
rspec-support (3.
|
92
|
-
rubocop (1.
|
116
|
+
rspec-support (~> 3.12.0)
|
117
|
+
rspec-support (3.12.1)
|
118
|
+
rubocop (1.56.2)
|
119
|
+
base64 (~> 0.1.1)
|
93
120
|
json (~> 2.3)
|
121
|
+
language_server-protocol (>= 3.17.0)
|
94
122
|
parallel (~> 1.10)
|
95
|
-
parser (>= 3.
|
123
|
+
parser (>= 3.2.2.3)
|
96
124
|
rainbow (>= 2.2.2, < 4.0)
|
97
125
|
regexp_parser (>= 1.8, < 3.0)
|
98
126
|
rexml (>= 3.2.5, < 4.0)
|
99
|
-
rubocop-ast (>= 1.
|
127
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
100
128
|
ruby-progressbar (~> 1.7)
|
101
|
-
unicode-display_width (>=
|
102
|
-
rubocop-ast (1.
|
103
|
-
parser (>= 3.
|
104
|
-
ruby-progressbar (1.
|
129
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
130
|
+
rubocop-ast (1.29.0)
|
131
|
+
parser (>= 3.2.1.0)
|
132
|
+
ruby-progressbar (1.13.0)
|
105
133
|
ruby2_keywords (0.0.5)
|
106
|
-
thor (1.2.
|
107
|
-
tzinfo (2.0.
|
134
|
+
thor (1.2.2)
|
135
|
+
tzinfo (2.0.6)
|
108
136
|
concurrent-ruby (~> 1.0)
|
109
|
-
unicode-display_width (2.
|
110
|
-
zeitwerk (2.6.
|
137
|
+
unicode-display_width (2.4.2)
|
138
|
+
zeitwerk (2.6.11)
|
111
139
|
|
112
140
|
PLATFORMS
|
113
141
|
arm64-darwin-20
|
142
|
+
arm64-darwin-22
|
114
143
|
x86_64-darwin-19
|
115
144
|
|
116
145
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -50,14 +50,23 @@ Rpdoc.configure do |config|
|
|
50
50
|
|
51
51
|
# (Optional) Collection name.
|
52
52
|
config.collection_name = 'Rpdoc'
|
53
|
+
|
54
|
+
# (Optional) Specs in folder are used for json data generation.
|
55
|
+
config.rspec_root = 'rspec'
|
53
56
|
|
54
57
|
# (Optional) Your Rails server API host.
|
55
58
|
config.rspec_server_host = '{{server_host}}'
|
56
59
|
|
57
|
-
# (Optional) Since Rspec generates many noisy headers, you can filter them.
|
60
|
+
# (Optional) Since Rspec generates many noisy request headers, you can filter them.
|
58
61
|
config.rspec_request_allow_headers = ['User-Agent', 'Content-Type', 'Authorization']
|
59
62
|
|
60
|
-
# (Optional)
|
63
|
+
# (Optional) Since Rspec generates many noisy response headers, you can filter them.
|
64
|
+
config.rspec_response_allow_headers = ['Content-Type', 'Content-Length', 'Location']
|
65
|
+
|
66
|
+
# (Optional) Rspec response identifier, including :rspec_location and nil.
|
67
|
+
config.rspec_response_identifier = :rspec_location
|
68
|
+
|
69
|
+
# (Optional) Root folder where Rpdoc saves generated json data.
|
61
70
|
config.rpdoc_root = 'rpdoc'
|
62
71
|
|
63
72
|
# (Optional) Filename to store RSpec request json data.
|
@@ -76,6 +85,9 @@ Rpdoc.configure do |config|
|
|
76
85
|
config.rpdoc_clean_empty_folders = true
|
77
86
|
config.rpdoc_clean_empty_folders_except = []
|
78
87
|
|
88
|
+
# (Optional) Folder ordering, including :asc, :desc, and custom array.
|
89
|
+
config.rpdoc_folder_ordering = :asc
|
90
|
+
|
79
91
|
# (Optional) Auto push strategy, including :push_and_create and :push_and_update
|
80
92
|
config.rpdoc_auto_push_strategy = :push_and_create
|
81
93
|
end
|
@@ -83,16 +95,16 @@ end
|
|
83
95
|
|
84
96
|
## Usage
|
85
97
|
|
86
|
-
`Rpdoc` only supports RSpec examples with [request](https://
|
98
|
+
`Rpdoc` only supports RSpec examples with [request](https://rspec.info/features/6-1/rspec-rails/request-specs/request-spec/) type.
|
87
99
|
|
88
|
-
1. Include [shared_context](https://
|
100
|
+
1. Include [shared_context](https://rspec.info/features/3-13/rspec-core/example-groups/shared-context/) in your spec to make `Rpdoc` identify which examples to transform.
|
89
101
|
```ruby
|
90
102
|
RSpec.describe 'POST /api/v1/books', type: :request do
|
91
103
|
include_context 'rpdoc'
|
92
104
|
...
|
93
105
|
end
|
94
106
|
```
|
95
|
-
2.
|
107
|
+
2. Customize your example [metdata](https://rspec.info/features/3-13/rspec-core/metadata/user-defined/) to generate collection data in your preferenced format.
|
96
108
|
```ruby
|
97
109
|
it 'should return 200' do |example|
|
98
110
|
# Request identifier.
|
@@ -132,9 +144,11 @@ end
|
|
132
144
|
|
133
145
|
4. You can write description for your Postman collection by creating markdown files (named `description.md`) and putting each of them in corresponding location under `rpdoc` folder.
|
134
146
|
|
147
|
+
5. You can manually push your collection to the Postman server through `rake rpdoc:push`.
|
148
|
+
|
135
149
|
## Notice
|
136
150
|
|
137
|
-
If you try to mock the `File.open` method, generating collection data will fail because creating `request.json`
|
151
|
+
If you try to mock the `File.open` method, generating collection data will fail because creating `request.json` uses the `File.open` method.
|
138
152
|
|
139
153
|
Solution:
|
140
154
|
|
data/Rakefile
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "bundler/
|
3
|
+
require "bundler/setup"
|
4
4
|
require "rubocop/rake_task"
|
5
5
|
|
6
6
|
RuboCop::RakeTask.new
|
7
7
|
|
8
8
|
task default: :rubocop
|
9
|
+
|
10
|
+
path = File.expand_path(__dir__)
|
11
|
+
Dir.glob("#{path}/lib/rpdoc/**/*.rake").each { |f| import f }
|
data/VERSION.md
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -16,14 +16,23 @@ Rpdoc.configure do |config|
|
|
16
16
|
|
17
17
|
# (Optional) Collection name.
|
18
18
|
# config.collection_name = 'Rpdoc'
|
19
|
+
|
20
|
+
# (Optional) Specs in folder are used for json data generation.
|
21
|
+
# config.rspec_root = 'spec'
|
19
22
|
|
20
23
|
# (Optional) Your Rails server API host.
|
21
24
|
# config.rspec_server_host = '{{server_host}}'
|
22
25
|
|
23
|
-
# (Optional) Since Rspec generates many noisy headers, you can filter them.
|
26
|
+
# (Optional) Since Rspec generates many noisy request headers, you can filter them.
|
24
27
|
# config.rspec_request_allow_headers = ['User-Agent', 'Content-Type', 'Authorization']
|
25
28
|
|
26
|
-
# (Optional)
|
29
|
+
# (Optional) Since Rspec generates many noisy response headers, you can filter them.
|
30
|
+
# config.rspec_response_allow_headers = ['Content-Type', 'Content-Length', 'Location']
|
31
|
+
|
32
|
+
# (Optional) Rspec response identifier, including :rspec_location and nil.
|
33
|
+
# config.rspec_response_identifier = :rspec_location
|
34
|
+
|
35
|
+
# (Optional) Root folder where Rpdoc saves generated json data.
|
27
36
|
# config.rpdoc_root = 'rpdoc'
|
28
37
|
|
29
38
|
# (Optional) Filename to store RSpec request json data.
|
@@ -39,6 +48,9 @@ Rpdoc.configure do |config|
|
|
39
48
|
# config.rpdoc_clean_empty_folders = true
|
40
49
|
# config.rpdoc_clean_empty_folders_except = []
|
41
50
|
|
51
|
+
# (Optional) Folder ordering, including :asc, :desc, and custom array.
|
52
|
+
# config.rpdoc_folder_ordering = :asc
|
53
|
+
|
42
54
|
# (Optional) Auto push collection to Postman server or not.
|
43
55
|
# config.rpdoc_auto_push = false
|
44
56
|
|
data/lib/rpdoc/configuration.rb
CHANGED
@@ -13,17 +13,25 @@ module Rpdoc
|
|
13
13
|
:collection_workspace,
|
14
14
|
:collection_uid,
|
15
15
|
:collection_name,
|
16
|
+
:rspec_root,
|
16
17
|
:rspec_server_host,
|
17
18
|
:rspec_request_allow_headers,
|
19
|
+
:rspec_response_allow_headers,
|
20
|
+
:rspec_response_identifier,
|
18
21
|
:rpdoc_root,
|
19
22
|
:rpdoc_request_filename,
|
20
23
|
:rpdoc_description_filename,
|
21
24
|
:rpdoc_collection_filename,
|
22
25
|
:rpdoc_clean_empty_folders,
|
23
26
|
:rpdoc_clean_empty_folders_except,
|
27
|
+
:rpdoc_folder_ordering,
|
24
28
|
:rpdoc_auto_push,
|
25
29
|
:rpdoc_auto_push_strategy
|
26
30
|
|
31
|
+
RSPEC_RESPONSE_IDENTIFIERS = [:rspec_location, nil].freeze
|
32
|
+
RPDOC_FOLDER_ORDERING = [:asc, :desc].freeze
|
33
|
+
RPDOC_AUTO_PUSH_STRATEGIES = [:push_and_create, :push_and_update].freeze
|
34
|
+
|
27
35
|
def initialize
|
28
36
|
@rpdoc_enable = ENV['RPDOC_ENABLE'] != 'false'
|
29
37
|
|
@@ -36,8 +44,11 @@ module Rpdoc
|
|
36
44
|
@collection_name = 'Rpdoc'
|
37
45
|
@collection_schema = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
|
38
46
|
|
47
|
+
@rspec_root = 'spec'
|
39
48
|
@rspec_server_host = '{{server_host}}'
|
40
49
|
@rspec_request_allow_headers = ['User-Agent', 'Content-Type', 'Authorization']
|
50
|
+
@rspec_response_allow_headers = ['Content-Type', 'Content-Length', 'Location']
|
51
|
+
@rspec_response_identifier = :rspec_location
|
41
52
|
|
42
53
|
@rpdoc_root = 'rpdoc'
|
43
54
|
@rpdoc_request_filename = 'request.json'
|
@@ -46,15 +57,19 @@ module Rpdoc
|
|
46
57
|
|
47
58
|
@rpdoc_clean_empty_folders = true
|
48
59
|
@rpdoc_clean_empty_folders_except = []
|
60
|
+
@rpdoc_folder_ordering = []
|
49
61
|
|
50
62
|
@rpdoc_auto_push = false
|
51
|
-
@rpdoc_auto_push_strategy = :push_and_create
|
63
|
+
@rpdoc_auto_push_strategy = :push_and_create
|
52
64
|
end
|
53
65
|
|
54
66
|
def valid?
|
55
67
|
return true unless @rpdoc_enable && @rpdoc_auto_push
|
56
68
|
return false if @postman_apikey.nil?
|
69
|
+
return false unless RSPEC_RESPONSE_IDENTIFIERS.include?(@rspec_response_identifier.to_sym)
|
70
|
+
return false unless RPDOC_AUTO_PUSH_STRATEGIES.include?(@rpdoc_auto_push_strategy.to_sym)
|
57
71
|
return false if @rpdoc_auto_push_strategy == :push_and_update && @collection_uid.nil?
|
72
|
+
return false if @rpdoc_folder_ordering.present? && (RPDOC_FOLDER_ORDERING.exclude?(@rpdoc_folder_ordering) || !@rpdoc_folder_ordering.is_a?(Array))
|
58
73
|
true
|
59
74
|
end
|
60
75
|
end
|
data/lib/rpdoc/helper.rb
CHANGED
@@ -25,12 +25,18 @@ end
|
|
25
25
|
RSpec.shared_context 'rpdoc' do
|
26
26
|
after(:each) do |example|
|
27
27
|
example.metadata[:rpdoc_skip] ||= false
|
28
|
-
|
28
|
+
|
29
|
+
example_usable = true
|
30
|
+
example_usable &&= example.metadata[:rpdoc_skip] == false
|
31
|
+
example_usable &&= File.expand_path(example.metadata[:file_path]).start_with?(File.expand_path(Rpdoc.configuration.rspec_root))
|
32
|
+
example_usable &&= example.exception.nil? && example.metadata[:type] == :request
|
33
|
+
|
34
|
+
if Rpdoc.configuration.rpdoc_enable && example_usable
|
29
35
|
example.metadata[:rpdoc_action_key] ||= controller.action_name
|
30
36
|
example.metadata[:rpdoc_action_name] ||= controller.action_name
|
31
37
|
example.metadata[:rpdoc_example_key] ||= example.metadata[:description].underscore
|
32
38
|
example.metadata[:rpdoc_example_name] ||= example.metadata[:description]
|
33
|
-
example.metadata[:rpdoc_example_folders] ||= controller.controller_path.split('/')
|
39
|
+
example.metadata[:rpdoc_example_folders] ||= controller.class.controller_path.split('/')
|
34
40
|
|
35
41
|
postman_response = Rpdoc::PostmanResponse.new(example, request, response)
|
36
42
|
postman_response.save
|
@@ -1,16 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json_requester'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
4
6
|
|
5
7
|
module Rpdoc
|
6
8
|
class PostmanCollection
|
9
|
+
attr_reader :data
|
7
10
|
|
8
|
-
def initialize
|
9
|
-
@configuration = Rpdoc.configuration
|
11
|
+
def initialize(configuration: nil, data: nil)
|
12
|
+
@configuration = configuration || Rpdoc.configuration
|
10
13
|
@requester = JsonRequester.new(@configuration.postman_host)
|
14
|
+
@data = data&.deep_symbolize_keys || generated_collection_data
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
self.clean_empty_folders!
|
17
|
+
self.reordering!
|
18
|
+
end
|
19
|
+
|
20
|
+
def push
|
21
|
+
send(@configuration.rpdoc_auto_push_strategy)
|
14
22
|
end
|
15
23
|
|
16
24
|
def push_and_create
|
@@ -28,18 +36,38 @@ module Rpdoc
|
|
28
36
|
}
|
29
37
|
remote_collection_data = @requester.http_send(:get, path, {}, headers)
|
30
38
|
remote_collection_data = remote_collection_data['status'] == 200 ? remote_collection_data.deep_symbolize_keys.slice(:collection) : nil
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@requester.http_send(:put, path,
|
39
|
+
remote_collection = PostmanCollection.new(data: remote_collection_data)
|
40
|
+
remote_collection.clean_generated_responses!
|
41
|
+
remote_collection.merge!(self)
|
42
|
+
@requester.http_send(:put, path, remote_collection.data, headers)
|
35
43
|
end
|
36
44
|
|
37
|
-
def save
|
38
|
-
|
45
|
+
def save(path: nil)
|
46
|
+
path ||= "#{@configuration.rpdoc_root}/#{@configuration.rpdoc_collection_filename}"
|
47
|
+
File.open(path, 'w+') do |f|
|
39
48
|
f.write(JSON.pretty_generate(@data))
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
52
|
+
def merge!(other_collection)
|
53
|
+
@data[:collection][:info][:name] = other_collection.data[:collection][:info][:name]
|
54
|
+
@data[:collection][:info][:description] = other_collection.data[:collection][:info][:description]
|
55
|
+
insert_generated_responses_into(@data[:collection][:item], from_collection_items: other_collection.data[:collection][:item].to_a)
|
56
|
+
sort_folders_from(@data[:collection][:item])
|
57
|
+
end
|
58
|
+
|
59
|
+
def clean_empty_folders!
|
60
|
+
clean_empty_folders_from(@data[:collection][:item])
|
61
|
+
end
|
62
|
+
|
63
|
+
def clean_generated_responses!
|
64
|
+
clean_generated_responses_from(@data[:collection][:item])
|
65
|
+
end
|
66
|
+
|
67
|
+
def reordering!
|
68
|
+
sort_folders_from(@data[:collection][:item])
|
69
|
+
end
|
70
|
+
|
43
71
|
private
|
44
72
|
|
45
73
|
def generated_collection_data
|
@@ -84,20 +112,13 @@ module Rpdoc
|
|
84
112
|
data
|
85
113
|
end
|
86
114
|
|
87
|
-
def merged_by(other_collection_data)
|
88
|
-
clean_generated_responses_from(other_collection_data[:collection][:item])
|
89
|
-
|
90
|
-
other_collection_data[:collection][:info][:description] = @data[:collection][:info][:description]
|
91
|
-
insert_generated_responses_into(other_collection_data[:collection][:item], from_collection_items: @data[:collection][:item])
|
92
|
-
end
|
93
|
-
|
94
115
|
def clean_generated_responses_from(collection_items)
|
95
116
|
collection_items.each do |item|
|
96
117
|
if item.has_key?(:item)
|
97
118
|
clean_generated_responses_from(item[:item])
|
98
119
|
elsif item.has_key?(:response)
|
99
120
|
item[:response].reject! do |response|
|
100
|
-
response.dig(:header)&.pluck(:key)&.include?('RSpec-Location')
|
121
|
+
@configuration.rspec_response_identifier.present? ? response.dig(:header)&.pluck(:key)&.include?('RSpec-Location') : true
|
101
122
|
end
|
102
123
|
end
|
103
124
|
end
|
@@ -105,7 +126,9 @@ module Rpdoc
|
|
105
126
|
|
106
127
|
def insert_generated_responses_into(collection_items, from_collection_items: [])
|
107
128
|
if collection_items.empty?
|
108
|
-
|
129
|
+
from_collection_items.each do |item|
|
130
|
+
collection_items << item.deep_dup
|
131
|
+
end
|
109
132
|
else
|
110
133
|
# transform collection_items into hash, using item[:name] as key
|
111
134
|
item_hash = {}
|
@@ -119,7 +142,7 @@ module Rpdoc
|
|
119
142
|
if item_hash.has_key?(from_item_name)
|
120
143
|
if from_item.has_key?(:item) && item_hash[from_item_name].has_key?(:item)
|
121
144
|
item_hash[from_item_name][:description] = from_item[:description]
|
122
|
-
insert_generated_responses_into(item_hash[from_item_name][:item], from_collection_items: from_item[:item])
|
145
|
+
insert_generated_responses_into(item_hash[from_item_name][:item], from_collection_items: from_item[:item].to_a)
|
123
146
|
elsif from_item.has_key?(:response) && item_hash[from_item_name].has_key?(:response)
|
124
147
|
item_hash[from_item_name][:request][:description] = from_item[:request][:description]
|
125
148
|
item_hash[from_item_name][:response] += from_item[:response].deep_dup
|
@@ -135,12 +158,24 @@ module Rpdoc
|
|
135
158
|
|
136
159
|
def clean_empty_folders_from(collection_items)
|
137
160
|
return unless @configuration.rpdoc_clean_empty_folders
|
138
|
-
collection_items
|
161
|
+
collection_items&.reject! do |item|
|
139
162
|
next false if item.has_key?(:request)
|
140
163
|
next false if @configuration.rpdoc_clean_empty_folders_except.include?(item[:name])
|
141
164
|
clean_empty_folders_from(item[:item]) if item[:item].present?
|
142
165
|
item[:item].nil? || item[:item].empty?
|
143
166
|
end
|
144
167
|
end
|
168
|
+
|
169
|
+
def sort_folders_from(collection_items)
|
170
|
+
return unless @configuration.rpdoc_folder_ordering.present?
|
171
|
+
if @configuration.rpdoc_folder_ordering == :asc
|
172
|
+
collection_items&.sort_by! { |item| item[:name] }
|
173
|
+
elsif @configuration.rpdoc_folder_ordering == :desc
|
174
|
+
collection_items&.sort_by! { |item| item[:name] }.reverse!
|
175
|
+
elsif @configuration.rpdoc_folder_ordering.is_a?(Array)
|
176
|
+
# sort by array and then sort by asc
|
177
|
+
collection_items&.sort_by! { |item| [@configuration.rpdoc_folder_ordering.index(item[:name]) || Float::INFINITY, item[:name]] }
|
178
|
+
end
|
179
|
+
end
|
145
180
|
end
|
146
181
|
end
|
@@ -38,26 +38,28 @@ module Rpdoc
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def response_data
|
41
|
-
|
42
|
-
headers
|
41
|
+
header = @rspec_response.header.slice(*@configuration.rspec_response_allow_headers) if @configuration.rspec_response_allow_headers.present?
|
42
|
+
headers = header.map { |key, value| { key: key, value: value } }
|
43
|
+
headers << rspec_response_identifier_header if @configuration.rspec_response_identifier.present?
|
43
44
|
data = {
|
44
45
|
name: @rspec_example.metadata[:rpdoc_example_name],
|
45
46
|
originalRequest: original_request_data,
|
46
47
|
status: @rspec_response.status.to_s,
|
47
48
|
code: @rspec_response.code.to_i,
|
48
|
-
_postman_previewlanguage: 'json',
|
49
49
|
header: headers,
|
50
50
|
}
|
51
51
|
if @rspec_response.headers['Content-Type'].include?('application/json')
|
52
|
+
data[:_postman_previewlanguage] = 'json'
|
52
53
|
data[:body] = JSON.pretty_generate(JSON.parse(@rspec_response.body)) rescue nil
|
53
54
|
else
|
54
55
|
body = @rspec_response.body
|
56
|
+
data[:_postman_previewlanguage] = 'text'
|
55
57
|
data[:body] = body.encoding == Encoding::BINARY ? (body.force_encoding(Encoding::ISO_8859_1).encode(Encoding::UTF_8) rescue body) : body
|
56
58
|
end
|
57
59
|
data
|
58
60
|
end
|
59
61
|
|
60
|
-
def
|
62
|
+
def rspec_response_identifier_header
|
61
63
|
{
|
62
64
|
key: 'RSpec-Location',
|
63
65
|
value: @rspec_example.metadata[:location]
|
data/lib/rpdoc/rpdoc.rake
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rpdoc'
|
4
|
+
|
1
5
|
namespace :rpdoc do
|
2
6
|
desc 'push collection to the Postman server'
|
3
|
-
task :push
|
7
|
+
task :push do
|
4
8
|
postman_collection = Rpdoc::PostmanCollection.new
|
5
9
|
postman_collection.save
|
6
10
|
postman_collection.send(Rpdoc.configuration.rpdoc_auto_push_strategy) if Rpdoc.configuration.rpdoc_auto_push
|
data/lib/rpdoc/version.rb
CHANGED
data/lib/rpdoc.rb
CHANGED
data/rpdoc.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
spec.add_dependency 'json_requester', '~> 1.0'
|
31
|
+
spec.add_dependency 'activesupport', '~> 6.1'
|
31
32
|
|
32
33
|
spec.add_development_dependency 'railties', '~> 6.1.4'
|
33
34
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yuntai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_requester
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: railties
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +126,7 @@ files:
|
|
112
126
|
- lib/rpdoc/helper.rb
|
113
127
|
- lib/rpdoc/postman_collection.rb
|
114
128
|
- lib/rpdoc/postman_response.rb
|
129
|
+
- lib/rpdoc/railtie.rb
|
115
130
|
- lib/rpdoc/rpdoc.rake
|
116
131
|
- lib/rpdoc/version.rb
|
117
132
|
- rpdoc.gemspec
|