dox 1.0.2 → 2.0.0.beta3
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 +5 -5
- data/.rubocop.yml +6 -3
- data/.ruby-version +1 -1
- data/.travis.yml +7 -11
- data/CHANGES.md +40 -0
- data/Gemfile +1 -1
- data/README.md +115 -116
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/dox.gemspec +14 -13
- data/lib/dox.rb +14 -1
- data/lib/dox/config.rb +38 -5
- data/lib/dox/dsl/action.rb +10 -4
- data/lib/dox/dsl/documentation.rb +4 -0
- data/lib/dox/dsl/syntax.rb +1 -0
- data/lib/dox/entities/action.rb +33 -12
- data/lib/dox/entities/example.rb +34 -10
- data/lib/dox/entities/resource.rb +4 -5
- data/lib/dox/entities/resource_group.rb +2 -3
- data/lib/dox/formatter.rb +22 -12
- data/lib/dox/formatters/base.rb +19 -0
- data/lib/dox/formatters/json.rb +14 -0
- data/lib/dox/formatters/multipart.rb +23 -0
- data/lib/dox/formatters/plain.rb +13 -0
- data/lib/dox/formatters/xml.rb +14 -0
- data/lib/dox/printers/action_printer.rb +18 -27
- data/lib/dox/printers/base_printer.rb +36 -17
- data/lib/dox/printers/document_printer.rb +27 -7
- data/lib/dox/printers/example_request_printer.rb +69 -0
- data/lib/dox/printers/example_response_printer.rb +86 -0
- data/lib/dox/printers/resource_group_printer.rb +7 -7
- data/lib/dox/printers/resource_printer.rb +12 -7
- data/lib/dox/util/http.rb +64 -0
- data/lib/dox/version.rb +1 -1
- metadata +91 -29
- data/lib/dox/printers/example_printer.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19d606ce8e741ff8f4844e0a0f2bff86cda870356417fb20254dad8030865f21
|
4
|
+
data.tar.gz: 3d57f29f50c860c4d5781e5990b398e984461d8b8239b3b82885d5df89fc8414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c520ed0ca05c9b2eab780ef3feef96a937277912ad97e460ded62cd4dfa2c455675a937ccb299b8776140b6f38657aacc67c3430e6c3e0004f7e2af53a20da3
|
7
|
+
data.tar.gz: 7b288f580fa957a06764cc9d0df09c6fb6d914d43743b4fe58ee0666f614e96ad34cdf9a0f90069d5805fa7360e124f922d658d7c485811e5c9a3afe01ca7d3c
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.5
|
data/.travis.yml
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
language: ruby
|
2
|
-
before_install: gem install bundler -v 1.
|
2
|
+
# before_install: gem install bundler -v 1.17.3
|
3
3
|
|
4
4
|
matrix:
|
5
5
|
include:
|
6
|
-
- rvm: 2.0.0
|
7
|
-
env: "RAILS_VERSION=4.0.0"
|
8
|
-
- rvm: 2.1.2
|
9
|
-
env: "RAILS_VERSION=4.1.0"
|
10
|
-
- rvm: 2.2.0
|
11
|
-
env: "RAILS_VERSION=4.2.0"
|
12
|
-
- rvm: 2.2.2
|
13
|
-
env: "RAILS_VERSION=5.0.0"
|
14
|
-
- rvm: 2.3.0
|
15
|
-
env: "RAILS_VERSION=5.0.0"
|
16
6
|
- rvm: 2.4.0
|
17
7
|
env: "RAILS_VERSION=5.0.0"
|
8
|
+
- rvm: 2.5.0
|
9
|
+
env: "RAILS_VERSION=5.0.0"
|
10
|
+
- rvm: 2.6.0
|
11
|
+
env: "RAILS_VERSION=6.0.0"
|
12
|
+
- rvm: 2.7.0
|
13
|
+
env: "RAILS_VERSION=6.0.0"
|
18
14
|
|
19
15
|
addons:
|
20
16
|
code_climate:
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,45 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 2.0.0
|
4
|
+
|
5
|
+
Released on August 8, 2020
|
6
|
+
|
7
|
+
Change:
|
8
|
+
- BREAKING CHANGE The API description format changed from API-blueprint to OpenAPI.
|
9
|
+
- BREAKING CHANGE Base structure is now defined in .json format
|
10
|
+
- BREAKING CHANGE Output is written to a .json file
|
11
|
+
- BREAKING CHANGE Html is rendered with Redoc instead of Aglio
|
12
|
+
- Renamed Dox.config.desc_folder_path -> Dox.config.descriptions_location
|
13
|
+
- Depricated Dox.config.header_file_path
|
14
|
+
|
15
|
+
New:
|
16
|
+
- Added Dox.config.title
|
17
|
+
- Added Dox.config.header_description
|
18
|
+
- Added Dox.config.version
|
19
|
+
|
20
|
+
## Version 1.2.0
|
21
|
+
|
22
|
+
Released on November 27, 2019
|
23
|
+
|
24
|
+
New:
|
25
|
+
- Support Multipart payload with pretty formatting (based on `content-type` header)
|
26
|
+
|
27
|
+
Fix:
|
28
|
+
- Explicit passing of an empty hash for `params` in actions now works as expected
|
29
|
+
|
30
|
+
|
31
|
+
## Version 1.1.0
|
32
|
+
|
33
|
+
Released on February 19, 2018
|
34
|
+
|
35
|
+
New:
|
36
|
+
- Full RSpec failure dump to stderr if any test fails when running tests with Dox::Formatter
|
37
|
+
- Support any payload format with pretty formatting for JSON and XML (based on `content-type` header)
|
38
|
+
|
39
|
+
Fix:
|
40
|
+
- Ignore subdomain request header in headers output
|
41
|
+
|
42
|
+
|
3
43
|
## Version 1.0.1
|
4
44
|
|
5
45
|
Released on June 10, 2017
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,13 +4,9 @@
|
|
4
4
|
|
5
5
|
# Dox
|
6
6
|
|
7
|
-
Automate your documentation writing
|
7
|
+
Automate your documentation writing process! Dox generates API documentation from Rspec controller/request specs in a Rails application. It formats the tests output in the [OpenApi](https://www.openapis.org/) format. Use the ReDoc renderer for generating and displaying the documentation as HTML.
|
8
8
|
|
9
|
-
Here's a [demo app](https://github.com/infinum/dox-demo)
|
10
|
-
|
11
|
-
- [Dox demo - Apiary](http://docs.doxdemo.apiary.io/#reference/books/books)
|
12
|
-
- [Dox demo - Aglio](https://infinum.github.io/dox-demo/aglio)
|
13
|
-
- [Dox demo - Snowboard](https://infinum.github.io/dox-demo/snowboard)
|
9
|
+
Here's a [demo app](https://github.com/infinum/dox-demo).
|
14
10
|
|
15
11
|
|
16
12
|
## Installation
|
@@ -19,7 +15,7 @@ Add this line to your application's Gemfile:
|
|
19
15
|
|
20
16
|
```ruby
|
21
17
|
group :test do
|
22
|
-
gem 'dox', require:
|
18
|
+
gem 'dox', require: false
|
23
19
|
end
|
24
20
|
```
|
25
21
|
|
@@ -44,39 +40,33 @@ $ gem install dox
|
|
44
40
|
require 'dox'
|
45
41
|
```
|
46
42
|
|
47
|
-
and configure rspec with this:
|
48
|
-
|
49
|
-
``` ruby
|
50
|
-
Rspec.configure do |config|
|
51
|
-
config.after(:each, :dox) do |example|
|
52
|
-
example.metadata[:request] = request
|
53
|
-
example.metadata[:response] = response
|
54
|
-
end
|
55
|
-
end
|
56
|
-
```
|
57
|
-
|
58
43
|
### Configure it
|
59
|
-
Set these
|
44
|
+
Set these optional options in the rails_helper:
|
60
45
|
|
61
46
|
| Option | Value | Description |
|
62
47
|
| -- | -- | -- |
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
|
70
|
-
|
|
48
|
+
| descriptions_location | Pathname instance or fullpath string | Folder containing markdown descriptions of resources. |
|
49
|
+
| schema_request_folder_path | Pathname instance or fullpath string | Folder with request schemas of resources. |
|
50
|
+
| schema_response_folder_path | Pathname instance or fullpath string | Folder with response schemas of resources. |
|
51
|
+
| schema_response_fail_file_path | Pathname instance or fullpath string | Json file that contains the default schema of a failed response. |
|
52
|
+
| openapi_version | string | Openapi version (default: '3.0.0' ) |
|
53
|
+
| api_version | string | Api Version (default: '1.0') |
|
54
|
+
| title | string | Documentation title (default: 'API Documentation') |
|
55
|
+
| header_description | Pathname instance or string | Description (header) of the documentation (default: ''). If pathname ends with `.md`, the file is looked in `descriptions_location` folder |
|
71
56
|
| headers_whitelist | Array of headers (strings) | Requests and responses will by default list only `Content-Type` header. To list other http headers, you must whitelist them.|
|
72
57
|
|
73
58
|
Example:
|
74
59
|
|
75
60
|
``` ruby
|
76
61
|
Dox.configure do |config|
|
77
|
-
config.
|
78
|
-
config.
|
62
|
+
config.descriptions_location = Rails.root.join('spec/docs/v1/descriptions')
|
63
|
+
config.schema_request_folder_path = Rails.root.join('spec/docs/v1/schemas')
|
64
|
+
config.schema_response_folder_path = Rails.root.join('spec/support/v1/schemas')
|
65
|
+
config.schema_response_fail_file_path = Rails.root.join('spec/support/v1/schemas/error.json')
|
79
66
|
config.headers_whitelist = ['Accept', 'X-Auth-Token']
|
67
|
+
config.title = 'API'
|
68
|
+
config.api_version = '2.0'
|
69
|
+
config.header_description = 'api_description.md'
|
80
70
|
end
|
81
71
|
```
|
82
72
|
|
@@ -95,6 +85,7 @@ module Docs
|
|
95
85
|
resource 'Bids' do
|
96
86
|
endpoint '/bids'
|
97
87
|
group 'Bids'
|
88
|
+
desc 'bids.md'
|
98
89
|
end
|
99
90
|
end
|
100
91
|
|
@@ -138,34 +129,41 @@ And [generate the documentation](#generate-documentation).
|
|
138
129
|
|
139
130
|
### Advanced options
|
140
131
|
|
141
|
-
Before running into any more details, here's roughly how
|
142
|
-
|
143
|
-
-
|
144
|
-
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
-
|
150
|
-
|
151
|
-
|
152
|
-
-
|
153
|
-
|
154
|
-
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
132
|
+
Before running into any more details, here's roughly how the generated OpenApi document is structured:
|
133
|
+
|
134
|
+
- openapi
|
135
|
+
- info
|
136
|
+
- paths
|
137
|
+
- action 1
|
138
|
+
- tag1
|
139
|
+
- example 1
|
140
|
+
- example 2
|
141
|
+
- action 2
|
142
|
+
- tag2
|
143
|
+
- example 3
|
144
|
+
- x-tagGroups
|
145
|
+
- tags1
|
146
|
+
- tag 1
|
147
|
+
- tag 2
|
148
|
+
- tags2
|
149
|
+
- tag 3
|
150
|
+
- tag 4
|
151
|
+
- tags
|
152
|
+
- tag1
|
153
|
+
- tag2
|
154
|
+
|
155
|
+
|
156
|
+
OpenApi and info are defined in a json file as mentioned before. Examples are concrete test examples (you can have multiple examples for both happy and fail paths). They are completely automatically generated from the request/response objects.
|
160
157
|
And you can customize the following in the descriptors:
|
161
158
|
|
162
|
-
-
|
163
|
-
- resource
|
159
|
+
- x-tagGroup (**resourceGroup**)
|
160
|
+
- tag (**resource**)
|
164
161
|
- action
|
162
|
+
- example
|
165
163
|
|
166
|
-
####
|
164
|
+
#### ResourceGroup
|
167
165
|
|
168
|
-
|
166
|
+
ResourceGroup contains related resources and is defined with:
|
169
167
|
- **name** (required)
|
170
168
|
- desc (optional, inline string or relative filepath)
|
171
169
|
|
@@ -198,7 +196,7 @@ document :bids do
|
|
198
196
|
end
|
199
197
|
```
|
200
198
|
|
201
|
-
Usually you'll want to define
|
199
|
+
Usually you'll want to define resourceGroup and resource together, so you don't have to include 2 modules with common data per spec file:
|
202
200
|
|
203
201
|
``` ruby
|
204
202
|
document :bids_common do
|
@@ -215,12 +213,16 @@ end
|
|
215
213
|
```
|
216
214
|
|
217
215
|
#### Action
|
218
|
-
Action is defined with:
|
216
|
+
Action contains examples and is defined with:
|
219
217
|
- **name** (required)
|
220
218
|
- path* (optional)
|
221
219
|
- verb* (optional)
|
222
|
-
- params
|
220
|
+
- params (optional; _depricated_)
|
221
|
+
- query_params (optional; [more info](https://swagger.io/docs/specification/describing-parameters/#query-parameters))
|
223
222
|
- desc (optional; inline string or relative filepath)
|
223
|
+
- request_schema (optional; inline string or relative filepath)
|
224
|
+
- response_schema_success (optional; inline string or relative filepath)
|
225
|
+
- response_schema_fail (optional; inline string or relative filepath)
|
224
226
|
|
225
227
|
\* these optional attributes are guessed (if not defined) from the request object of the test example and you can override them.
|
226
228
|
|
@@ -228,13 +230,37 @@ Example:
|
|
228
230
|
|
229
231
|
``` ruby
|
230
232
|
show_params = { id: { type: :number, required: :required, value: 1, description: 'bid id' } }
|
233
|
+
query_params = [ {
|
234
|
+
"in": "query",
|
235
|
+
"name": "filter",
|
236
|
+
"required": false,
|
237
|
+
"style": "deepObject",
|
238
|
+
"explode": true,
|
239
|
+
"schema": {
|
240
|
+
"type": "object",
|
241
|
+
"required": ["updated_at_gt"],
|
242
|
+
"example": {
|
243
|
+
"updated_at_gt": "2018-02-03 10:30:00"
|
244
|
+
},
|
245
|
+
"properties": {
|
246
|
+
"updated_at_gt": {
|
247
|
+
"type": "string",
|
248
|
+
"title": "date"
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
]
|
231
253
|
|
232
254
|
document :action do
|
233
255
|
action 'Get bid' do
|
234
256
|
path '/bids/{id}'
|
235
257
|
verb 'GET'
|
236
258
|
params show_params
|
259
|
+
query_params query_params
|
237
260
|
desc 'Some description for get bid action'
|
261
|
+
request_schema 'namespace/bids'
|
262
|
+
response_schema_success 'namespace/bids_s'
|
263
|
+
response_schema_fail 'namespace/bids_f'
|
238
264
|
end
|
239
265
|
end
|
240
266
|
```
|
@@ -242,89 +268,63 @@ end
|
|
242
268
|
### Generate documentation
|
243
269
|
Documentation is generated in 2 steps:
|
244
270
|
|
245
|
-
1. generate
|
246
|
-
```bundle exec rspec
|
271
|
+
1. generate OpenApi json file:
|
272
|
+
```bundle exec rspec --tag apidoc -f Dox::Formatter --order defined --tag dox --out spec/api_doc/v1/schemas/docs.json```
|
247
273
|
|
248
|
-
2. render HTML with
|
249
|
-
```
|
274
|
+
2. render HTML with Redoc:
|
275
|
+
```redoc-cli bundle -o public/api/docs/v2/docs.html spec/api_doc/v1/schemas/docs.json```
|
250
276
|
|
251
277
|
|
252
|
-
#### Use
|
253
|
-
It's recommendable to write a few
|
278
|
+
#### Use rake tasks
|
279
|
+
It's recommendable to write a few rake tasks to make things easier. Here's an example:
|
254
280
|
|
255
281
|
```ruby
|
256
|
-
namespace :
|
257
|
-
|
258
|
-
desc 'Generate API documentation markdown'
|
259
|
-
task :md do
|
260
|
-
require 'rspec/core/rake_task'
|
261
|
-
|
262
|
-
RSpec::Core::RakeTask.new(:api_spec) do |t|
|
263
|
-
t.pattern = 'spec/controllers/api/v1/'
|
264
|
-
t.rspec_opts = "-f Dox::Formatter --order defined --tag dox --out public/api/docs/v1/apispec.md"
|
265
|
-
end
|
282
|
+
namespace :dox do
|
283
|
+
desc 'Generate API documentation markdown'
|
266
284
|
|
267
|
-
|
268
|
-
|
285
|
+
task :json, [:version, :docs_path, :host] => :environment do |_, args|
|
286
|
+
require 'rspec/core/rake_task'
|
287
|
+
version = args[:version] || :v1
|
269
288
|
|
270
|
-
|
271
|
-
|
289
|
+
RSpec::Core::RakeTask.new(:api_spec) do |t|
|
290
|
+
t.pattern = "spec/requests/api/#{version}"
|
291
|
+
t.rspec_opts =
|
292
|
+
"-f Dox::Formatter --tag dox --order defined --out spec/docs/#{version}/apispec.json"
|
272
293
|
end
|
273
294
|
|
274
|
-
|
275
|
-
|
276
|
-
end
|
295
|
+
Rake::Task['api_spec'].invoke
|
296
|
+
end
|
277
297
|
|
278
|
-
|
279
|
-
|
280
|
-
|
298
|
+
task :html, [:version, :docs_path, :host] => :json do |_, args|
|
299
|
+
version = args[:version] || :v1
|
300
|
+
docs_path = args[:docs_path] || "api/#{version}/docs"
|
301
|
+
|
302
|
+
`yarn run redoc-cli bundle -o public/#{docs_path}/index.html spec/docs/#{version}/apispec.json`
|
303
|
+
end
|
304
|
+
|
305
|
+
task :open, [:version, :docs_path, :host] => :html do |_, args|
|
306
|
+
version = args[:version] || :v1
|
307
|
+
docs_path = args[:docs_path] || "api/#{version}/docs"
|
308
|
+
|
309
|
+
`open public/#{docs_path}/index.html`
|
281
310
|
end
|
282
311
|
end
|
283
312
|
```
|
284
313
|
|
285
314
|
#### Renderers
|
286
|
-
You can render the HTML yourself with
|
287
|
-
|
288
|
-
- [Aglio](https://github.com/danielgtaylor/aglio)
|
289
|
-
- [Snowboard](https://github.com/subosito/snowboard)
|
290
|
-
|
291
|
-
Both support multiple themes and template customization.
|
292
|
-
|
293
|
-
Or you can just take your generated markdown and host your documentation on [Apiary.io](https://apiary.io).
|
315
|
+
You can render the HTML yourself with ReDoc:
|
294
316
|
|
317
|
+
- [Redoc](https://github.com/Redocly/redoc)
|
295
318
|
|
296
319
|
### Common issues
|
297
320
|
|
298
321
|
You might experience some strange issues when generating the documentation. Here are a few examples of what we've encountered so far.
|
299
322
|
|
300
|
-
####
|
301
|
-
Rails wraps JSON parameters on all requests by default, which results with documented requests looking like this:
|
302
|
-
|
303
|
-
```
|
304
|
-
+ Request get pokemons
|
305
|
-
{
|
306
|
-
"pokemon": {}
|
307
|
-
}
|
308
|
-
```
|
309
|
-
|
310
|
-
To disable wrapping parameters with a resource name, turn off this feature in `config/initializers/wrap_parameters.rb`:
|
311
|
-
|
312
|
-
``` ruby
|
313
|
-
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
314
|
-
ActiveSupport.on_load(:action_controller) do
|
315
|
-
wrap_parameters format: []
|
316
|
-
end
|
317
|
-
```
|
318
|
-
|
319
|
-
#### Rendering warnings with Aglio
|
320
|
-
You might get the following warnings when rendering HTML with Aglio:
|
321
|
-
|
322
|
-
* `no headers specified (warning code 3)`
|
323
|
-
* `empty request message-body (warning code 6)`
|
324
|
-
|
325
|
-
This usually happens on GET requests examples when there are no headers. To solve this issue, add at least one header to the tests' requests, like `Accept: application/json`.
|
323
|
+
#### Uninitialized constant errors
|
326
324
|
|
325
|
+
There seems to be a problem with **rspec-rails** versions 3.7 and later not automatically requiring the project's rails_helper.rb when run with the `--format` flag.
|
327
326
|
|
327
|
+
To fix this issue, generate your documentation with `--require rails_helper`:
|
328
328
|
## Development
|
329
329
|
|
330
330
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -344,4 +344,3 @@ Dox is maintained and sponsored by [Infinum](https://infinum.co).
|
|
344
344
|
## License
|
345
345
|
|
346
346
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
347
|
-
|