dox 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module Dox
3
3
  class ResourceGroupPrinter < BasePrinter
4
4
  def print(resource_group)
5
5
  self.resource_group = resource_group
6
- @output.puts resource_group_title
6
+ add_resource_group
7
7
 
8
8
  resource_group.resources.each do |_, resource|
9
9
  resource_printer.print(resource)
@@ -14,16 +14,16 @@ module Dox
14
14
 
15
15
  attr_accessor :resource_group
16
16
 
17
- def resource_group_title
18
- <<-HEREDOC
17
+ def add_resource_group
18
+ spec['x-tagGroups'].push(name: resource_group.name, 'tags' => []) unless group_included?
19
+ end
19
20
 
20
- # Group #{resource_group.name}
21
- #{print_desc(resource_group.desc)}
22
- HEREDOC
21
+ def group_included?
22
+ spec['x-tagGroups'].find { |group| group[:name] == resource_group.name }
23
23
  end
24
24
 
25
25
  def resource_printer
26
- @resource_printer ||= ResourcePrinter.new(@output)
26
+ @resource_printer ||= ResourcePrinter.new(spec)
27
27
  end
28
28
  end
29
29
  end
@@ -3,7 +3,7 @@ module Dox
3
3
  class ResourcePrinter < BasePrinter
4
4
  def print(resource)
5
5
  self.resource = resource
6
- @output.puts resource_title
6
+ add_resources
7
7
 
8
8
  resource.actions.each do |_, action|
9
9
  action_printer.print(action)
@@ -14,16 +14,21 @@ module Dox
14
14
 
15
15
  attr_accessor :resource
16
16
 
17
- def resource_title
18
- <<-HEREDOC
17
+ def add_resources
18
+ add_to_tags
19
+ add_to_groups
20
+ end
21
+
22
+ def add_to_tags
23
+ spec['tags'] = spec['tags'].push(name: resource.name, description: format_desc(resource.desc)).uniq
24
+ end
19
25
 
20
- ## #{resource.name} [#{resource.endpoint}]
21
- #{print_desc(resource.desc)}
22
- HEREDOC
26
+ def add_to_groups
27
+ spec['x-tagGroups'].find { |group| group[:name] == resource.group }['tags'].push(resource.name)
23
28
  end
24
29
 
25
30
  def action_printer
26
- @action_printer ||= ActionPrinter.new(@output)
31
+ @action_printer ||= ActionPrinter.new(spec['paths'])
27
32
  end
28
33
  end
29
34
  end
data/lib/dox/util/http.rb CHANGED
@@ -2,6 +2,70 @@ module Dox
2
2
  module Util
3
3
  module Http
4
4
  VERB = ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'HEAD'].freeze
5
+ HTTP_STATUS_CODES = {
6
+ 100 => 'Continue',
7
+ 101 => 'Switching Protocols',
8
+ 102 => 'Processing',
9
+ 103 => 'Early Hints',
10
+ 200 => 'OK',
11
+ 201 => 'Created',
12
+ 202 => 'Accepted',
13
+ 203 => 'Non-Authoritative Information',
14
+ 204 => 'No Content',
15
+ 205 => 'Reset Content',
16
+ 206 => 'Partial Content',
17
+ 207 => 'Multi-Status',
18
+ 208 => 'Already Reported',
19
+ 226 => 'IM Used',
20
+ 300 => 'Multiple Choices',
21
+ 301 => 'Moved Permanently',
22
+ 302 => 'Found',
23
+ 303 => 'See Other',
24
+ 304 => 'Not Modified',
25
+ 305 => 'Use Proxy',
26
+ 307 => 'Temporary Redirect',
27
+ 308 => 'Permanent Redirect',
28
+ 400 => 'Bad Request',
29
+ 401 => 'Unauthorized',
30
+ 402 => 'Payment Required',
31
+ 403 => 'Forbidden',
32
+ 404 => 'Not Found',
33
+ 405 => 'Method Not Allowed',
34
+ 406 => 'Not Acceptable',
35
+ 407 => 'Proxy Authentication Required',
36
+ 408 => 'Request Timeout',
37
+ 409 => 'Conflict',
38
+ 410 => 'Gone',
39
+ 411 => 'Length Required',
40
+ 412 => 'Precondition Failed',
41
+ 413 => 'Payload Too Large',
42
+ 414 => 'URI Too Long',
43
+ 415 => 'Unsupported Media Type',
44
+ 416 => 'Range Not Satisfiable',
45
+ 417 => 'Expectation Failed',
46
+ 421 => 'Misdirected Request',
47
+ 422 => 'Unprocessable Entity',
48
+ 423 => 'Locked',
49
+ 424 => 'Failed Dependency',
50
+ 425 => 'Too Early',
51
+ 426 => 'Upgrade Required',
52
+ 428 => 'Precondition Required',
53
+ 429 => 'Too Many Requests',
54
+ 431 => 'Request Header Fields Too Large',
55
+ 451 => 'Unavailable for Legal Reasons',
56
+ 500 => 'Internal Server Error',
57
+ 501 => 'Not Implemented',
58
+ 502 => 'Bad Gateway',
59
+ 503 => 'Service Unavailable',
60
+ 504 => 'Gateway Timeout',
61
+ 505 => 'HTTP Version Not Supported',
62
+ 506 => 'Variant Also Negotiates',
63
+ 507 => 'Insufficient Storage',
64
+ 508 => 'Loop Detected',
65
+ 509 => 'Bandwidth Limit Exceeded',
66
+ 510 => 'Not Extended',
67
+ 511 => 'Network Authentication Required'
68
+ }.freeze
5
69
 
6
70
  def self.verb?(value)
7
71
  VERB.include?(value.upcase)
data/lib/dox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dox
2
- VERSION = '1.1.0'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,60 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melita Kokot
8
8
  - Vedran Hrnčić
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-02-19 00:00:00.000000000 Z
12
+ date: 2021-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.11'
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '1.11'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
29
+ name: codeclimate-test-reporter
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '10.0'
34
+ version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '10.0'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rspec
43
+ name: json
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '3.0'
48
+ version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '3.0'
55
+ version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: pry
57
+ name: pry-nav
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
@@ -68,7 +68,7 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: simplecov
71
+ name: pry-rails
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: codeclimate-test-reporter
85
+ name: pry-stack_explorer
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,34 +96,90 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: rspec-core
99
+ name: rails
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: '4.0'
105
105
  type: :runtime
106
106
  prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '4.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rake
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
108
122
  requirements:
109
123
  - - ">="
110
124
  - !ruby/object:Gem::Version
111
125
  version: '0'
112
126
  - !ruby/object:Gem::Dependency
113
- name: rails
127
+ name: rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rubocop
114
142
  requirement: !ruby/object:Gem::Requirement
115
143
  requirements:
116
144
  - - ">="
117
145
  - !ruby/object:Gem::Version
118
- version: '4.0'
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: simplecov
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: rspec-core
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
119
175
  type: :runtime
120
176
  prerelease: false
121
177
  version_requirements: !ruby/object:Gem::Requirement
122
178
  requirements:
123
179
  - - ">="
124
180
  - !ruby/object:Gem::Version
125
- version: '4.0'
126
- description:
181
+ version: '0'
182
+ description:
127
183
  email:
128
184
  - melita.kokot@gmail.com
129
185
  - vrabac266@gmail.com
@@ -166,10 +222,16 @@ files:
166
222
  - lib/dox/errors/invalid_resource_error.rb
167
223
  - lib/dox/errors/invalid_resource_group_error.rb
168
224
  - lib/dox/formatter.rb
225
+ - lib/dox/formatters/base.rb
226
+ - lib/dox/formatters/json.rb
227
+ - lib/dox/formatters/multipart.rb
228
+ - lib/dox/formatters/plain.rb
229
+ - lib/dox/formatters/xml.rb
169
230
  - lib/dox/printers/action_printer.rb
170
231
  - lib/dox/printers/base_printer.rb
171
232
  - lib/dox/printers/document_printer.rb
172
- - lib/dox/printers/example_printer.rb
233
+ - lib/dox/printers/example_request_printer.rb
234
+ - lib/dox/printers/example_response_printer.rb
173
235
  - lib/dox/printers/resource_group_printer.rb
174
236
  - lib/dox/printers/resource_printer.rb
175
237
  - lib/dox/util/http.rb
@@ -179,7 +241,7 @@ licenses:
179
241
  - MIT
180
242
  metadata:
181
243
  allowed_push_host: https://rubygems.org
182
- post_install_message:
244
+ post_install_message:
183
245
  rdoc_options: []
184
246
  require_paths:
185
247
  - lib
@@ -194,9 +256,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
256
  - !ruby/object:Gem::Version
195
257
  version: '0'
196
258
  requirements: []
197
- rubyforge_project:
198
- rubygems_version: 2.5.1
199
- signing_key:
259
+ rubygems_version: 3.0.3
260
+ signing_key:
200
261
  specification_version: 4
201
- summary: Generates API documentation for rspec in api blueprint format.
262
+ summary: Generates API documentation for rspec in OpenAPI format.
202
263
  test_files: []
@@ -1,132 +0,0 @@
1
- require 'rexml/document'
2
-
3
- module Dox
4
- module Printers
5
- class ExamplePrinter < BasePrinter
6
- def print(example)
7
- self.example = example
8
- print_example_request
9
- print_example_response
10
- end
11
-
12
- private
13
-
14
- attr_accessor :example
15
-
16
- def print_example_request
17
- @output.puts example_request_title
18
- @output.puts example_request_headers
19
- return unless example.request_body.present?
20
-
21
- @output.puts example_request_body
22
- end
23
-
24
- def print_example_response
25
- @output.puts example_response_title
26
-
27
- if example.response_headers.present?
28
- @output.puts example_response_headers
29
- end
30
-
31
- return unless example.response_body.present?
32
- @output.puts example_response_body
33
- end
34
-
35
- def example_request_title
36
- <<-HEREDOC
37
-
38
- + Request #{example.request_identifier}
39
- **#{example.request_method.upcase}**&nbsp;&nbsp;`#{CGI.unescape(example.request_fullpath)}`
40
- HEREDOC
41
- end
42
-
43
- def example_request_headers
44
- <<-HEREDOC
45
-
46
- + Headers
47
-
48
- #{indent_lines(12, print_headers(example.request_headers))}
49
- HEREDOC
50
- end
51
-
52
- def example_request_body
53
- <<-HEREDOC
54
-
55
- + Body
56
-
57
- #{indent_lines(12, formatted_body(example.request_body, example.request_content_type))}
58
- HEREDOC
59
- end
60
-
61
- def example_response_title
62
- <<-HEREDOC
63
-
64
- + Response #{example.response_status}
65
- HEREDOC
66
- end
67
-
68
- def example_response_headers
69
- <<-HEREDOC
70
-
71
- + Headers
72
-
73
- #{indent_lines(12, print_headers(example.response_headers))}
74
- HEREDOC
75
- end
76
-
77
- def example_response_body
78
- <<-HEREDOC
79
-
80
- + Body
81
-
82
- #{indent_lines(12, formatted_body(example.response_body, example.response_content_type))}
83
- HEREDOC
84
- end
85
-
86
- def formatted_body(body_str, content_type)
87
- case content_type
88
- when %r{application\/.*json}
89
- pretty_json(safe_json_parse(body_str))
90
- when /xml/
91
- pretty_xml(body_str)
92
- else
93
- body_str
94
- end
95
- end
96
-
97
- def safe_json_parse(json_string)
98
- json_string.length >= 2 ? JSON.parse(json_string) : nil
99
- end
100
-
101
- def pretty_json(json_string)
102
- if json_string.present?
103
- JSON.pretty_generate(json_string)
104
- else
105
- ''
106
- end
107
- end
108
-
109
- def pretty_xml(xml_string)
110
- doc = REXML::Document.new(xml_string)
111
- formatter = REXML::Formatters::Pretty.new
112
- formatter.compact = true
113
- result = ''
114
- formatter.write(doc, result)
115
- result
116
- end
117
-
118
- def print_headers(headers)
119
- headers.map do |key, value|
120
- "#{key}: #{value}"
121
- end.join("\n")
122
- end
123
-
124
- def indent_lines(number_of_spaces, string)
125
- string
126
- .split("\n")
127
- .map { |a| a.prepend(' ' * number_of_spaces) }
128
- .join("\n")
129
- end
130
- end
131
- end
132
- end