dox 1.2.0 → 2.0.0.beta1

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
- SHA1:
3
- metadata.gz: 1ff74ac34c68966c8eeb8ae9de609bd4eca79e4d
4
- data.tar.gz: 4df71ab4f1315a7e1947fd94c2e4ff156a3fab25
2
+ SHA256:
3
+ metadata.gz: 577100012c2891a9091b7d4f74e5fafee22b34cf06a24556b97f198fc6494a9b
4
+ data.tar.gz: beba05a5c7da69be18710b909c6d652694c3f02b0d73b256fa4f78ba19f22b9c
5
5
  SHA512:
6
- metadata.gz: 6140c2ebe30c6bb2cf621a480dfb1bf06c3caac0c4b337ba74089ae804c0cd5bfc80d3651c51d552cd020169bb50e5ef72ab77094341b8d13f293112edaeb14d
7
- data.tar.gz: da8ec16081224370f2afed78fe15963a9c2f8bd6f45189faf966f8770fb02b33924bd7792a093a7dd0c148484175697e6e1cc4eed9fce0fd769a63170aea762a
6
+ metadata.gz: ade817bb2361ba7560de8b2c67e51cdd3775adbdb310d87f91ec08d894d4e4cd9ad3e04138c5a6536a4fa5d9c875522c16a86c419524b9ba6fc49874be45368f
7
+ data.tar.gz: 715f4f73fa4547b2ae9b83e8ec7040cf11408dace456bed776ab39b64997c7bb78b498fa689c3d7cb3f50e8d1cfaf3c80f15c97104dee1ba96e99e0590e9cc85
@@ -7,8 +7,11 @@ Documentation:
7
7
  WordArray:
8
8
  Enabled: False
9
9
 
10
- AllCops:
11
- TargetRubyVersion: 2.3
12
-
13
10
  Style/FrozenStringLiteralComment:
14
11
  Enabled: false
12
+
13
+ BlockLength:
14
+ Max: 250
15
+
16
+ Gemspec/RequiredRubyVersion:
17
+ Enabled: false
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.5.5
@@ -1,20 +1,16 @@
1
1
  language: ruby
2
- before_install: gem install bundler -v 1.11.2
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,22 @@
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
+
3
20
  ## Version 1.2.0
4
21
 
5
22
  Released on November 27, 2019
data/Gemfile CHANGED
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in dox.gemspec
4
4
  gemspec
5
5
 
6
- rails_version = ENV['RAILS_VERSION'] || '5.0.1'
6
+ rails_version = ENV['RAILS_VERSION'] || '6.0.2'
7
7
 
8
8
  gem 'rails', "~> #{rails_version}"
data/README.md CHANGED
@@ -4,13 +4,9 @@
4
4
 
5
5
  # Dox
6
6
 
7
- Automate your documentation writing process! Dox generates API documentation from Rspec controller/request specs in a Rails application. It formats the test's output in the [API Blueprint](https://apiblueprint.org) format. Choose one of the [renderers](#renderers) to convert it to HTML or host it on [Apiary.io](https://apiary.io)
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) and here are some examples:
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
@@ -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 mandatory options in the rails_helper:
44
+ Set these optional options in the rails_helper:
60
45
 
61
46
  | Option | Value | Description |
62
47
  | -- | -- | -- |
63
- | header_file_path | Pathname instance or fullpath string | Markdown file that will be included at the top of the documentation. It should contain title and some basic info about the api. |
64
- | desc_folder_path | Pathname instance or fullpath string | Folder with markdown descriptions. |
65
-
66
-
67
- Optional settings:
68
-
69
- | Option | Value| Description |
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.header_file_path = Rails.root.join('spec/docs/v1/descriptions/header.md')
78
- config.desc_folder_path = Rails.root.join('spec/docs/v1/descriptions')
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 is the generated API Blueprint document structured:
142
-
143
- - header
144
- - resource group
145
- - resource
146
- - action
147
- - example 1
148
- - example 2
149
- - action
150
- - ...
151
- - resource
152
- - action
153
- - ...
154
- - resource group
155
- - resource
156
- - action
157
-
158
-
159
- Header is defined in a markdown file as mentioned before. Examples are concrete test examples (you can have 2 examples for create 1 happy path, 1 fail path). They are completely automatically generated from the request/response objects.
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
- - resource group
163
- - resource
159
+ - x-tagGroup (**resourceGroup**)
160
+ - tag (**resource**)
164
161
  - action
162
+ - example
165
163
 
166
- #### Resource group
164
+ #### ResourceGroup
167
165
 
168
- Resource group contains related resources and is defined with:
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 resource and resource group together, so you don't have to include 2 modules with common data per spec file:
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* (optional)
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,11 +268,11 @@ end
242
268
  ### Generate documentation
243
269
  Documentation is generated in 2 steps:
244
270
 
245
- 1. generate API Blueprint markdown:
246
- ```bundle exec rspec spec/controllers/api/v1 -f Dox::Formatter --order defined --tag dox --out docs.md```
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 some renderer, for example, with Aglio:
249
- ```aglio -i docs.md -o docs.html```
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
278
  #### Use rake tasks
@@ -256,42 +282,32 @@ It's recommendable to write a few rake tasks to make things easier. Here's an ex
256
282
  namespace :api do
257
283
  namespace :doc do
258
284
  desc 'Generate API documentation markdown'
259
- task :md do
285
+ task :json do
260
286
  require 'rspec/core/rake_task'
261
287
 
262
288
  RSpec::Core::RakeTask.new(:api_spec) do |t|
263
289
  t.pattern = 'spec/controllers/api/v1/'
264
- t.rspec_opts = "-f Dox::Formatter --order defined --tag dox --out public/api/docs/v1/apispec.md"
290
+ t.rspec_opts = "-f Dox::Formatter --order defined --tag dox --out public/api/docs/v1/docs.json"
265
291
  end
266
292
 
267
293
  Rake::Task['api_spec'].invoke
268
294
  end
269
295
 
270
- task html: :md do
271
- `aglio -i public/api/docs/v1/apispec.md -o public/api/docs/v1/index.html`
296
+ task html: :json do
297
+ `redoc-cli bundle -o public/api/docs/v2/index.html spec/api_doc/v1/schemas/docs.json`
272
298
  end
273
299
 
274
300
  task open: :html do
275
301
  `open public/api/docs/v1/index.html`
276
302
  end
277
-
278
- task publish: :md do
279
- `apiary publish --path=public/api/docs/v1/apispec.md --api-name=doxdemo`
280
- end
281
303
  end
282
304
  end
283
305
  ```
284
306
 
285
307
  #### Renderers
286
- You can render the HTML yourself with one of the renderers:
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).
308
+ You can render the HTML yourself with ReDoc:
294
309
 
310
+ - [Redoc](https://github.com/Redocly/redoc)
295
311
 
296
312
  ### Common issues
297
313
 
@@ -302,39 +318,6 @@ You might experience some strange issues when generating the documentation. Here
302
318
  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.
303
319
 
304
320
  To fix this issue, generate your documentation with `--require rails_helper`:
305
-
306
- ```
307
- bundle exec rspec -f Dox::Formatter --order defined --tag dox --out docs.md --require rails_helper
308
- ```
309
-
310
- #### Wrap parameters issue
311
- Rails wraps JSON parameters on all requests by default, which results with documented requests looking like this:
312
-
313
- ```
314
- + Request get pokemons
315
- {
316
- "pokemon": {}
317
- }
318
- ```
319
-
320
- To disable wrapping parameters with a resource name, turn off this feature in `config/initializers/wrap_parameters.rb`:
321
-
322
- ``` ruby
323
- # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
324
- ActiveSupport.on_load(:action_controller) do
325
- wrap_parameters format: []
326
- end
327
- ```
328
-
329
- #### Rendering warnings with Aglio
330
- You might get the following warnings when rendering HTML with Aglio:
331
-
332
- * `no headers specified (warning code 3)`
333
- * `empty request message-body (warning code 6)`
334
-
335
- 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`.
336
-
337
-
338
321
  ## Development
339
322
 
340
323
  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.
@@ -354,4 +337,3 @@ Dox is maintained and sponsored by [Infinum](https://infinum.co).
354
337
  ## License
355
338
 
356
339
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
357
-
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "dox"
3
+ require 'bundler/setup'
4
+ require 'dox'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "dox"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'dox/version'
5
4
 
@@ -9,31 +8,33 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ['Melita Kokot', 'Vedran Hrnčić']
10
9
  spec.email = ['melita.kokot@gmail.com', 'vrabac266@gmail.com']
11
10
 
12
- spec.summary = 'Generates API documentation for rspec in api blueprint format.'
11
+ spec.summary = 'Generates API documentation for rspec in OpenAPI format.'
13
12
  spec.homepage = 'https://github.com/infinum/dox'
14
13
  spec.license = 'MIT'
15
14
 
16
- spec.required_ruby_version = '>=2.0.0'
15
+ spec.required_ruby_version = '>= 2.0.0'
17
16
 
18
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
18
  # delete this section to allow pushing this gem to any host.
20
- if spec.respond_to?(:metadata)
21
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
- else
23
- raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
24
- end
19
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
20
+
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
22
 
26
23
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
24
  spec.bindir = 'exe'
28
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
26
  spec.require_paths = ['lib']
30
27
 
31
- spec.add_development_dependency 'bundler', '~> 1.11'
28
+ spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'codeclimate-test-reporter'
30
+ spec.add_development_dependency 'json'
31
+ spec.add_development_dependency 'pry-nav'
32
+ spec.add_development_dependency 'pry-rails'
33
+ spec.add_development_dependency 'pry-stack_explorer'
34
+ spec.add_runtime_dependency 'rails', '>= 4.0'
32
35
  spec.add_development_dependency 'rake', '~> 10.0'
33
36
  spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'rubocop'
35
38
  spec.add_development_dependency 'simplecov'
36
- spec.add_development_dependency 'codeclimate-test-reporter'
37
39
  spec.add_runtime_dependency 'rspec-core'
38
- spec.add_runtime_dependency 'rails', '>= 4.0'
39
40
  end