betterdocs 0.9.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +2 -2
- data/README.md +9 -0
- data/VERSION +1 -1
- data/betterdocs.gemspec +4 -4
- data/lib/betterdocs/dsl/controller/action/response.rb +5 -1
- data/lib/betterdocs/generator/markdown.rb +1 -1
- data/lib/betterdocs/version.rb +1 -1
- data/spec/betterdocs/dsl/controller/action/response_spec.rb +11 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad6f53d72b6b1dc91c3464a277c97992814fcc8b34a55f1fd043ace97b58c27a
|
4
|
+
data.tar.gz: '0259b534dece36526365a0861d2750c5ac5c5446e24920ef4113f67d4f00103a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8489c381f2cff832c4552f109f05c15fe092b95ea688025e98ef987ea4c714425dd981897b177ad6ad49d046c3166b20fb1cf10ac517a564373ca8080172fc89
|
7
|
+
data.tar.gz: a9858527e935a0ed22f82f218907a4010ad86a523de7504afa55890bc4dfed66a00347cec4f0ebe0aa7dd8587ec43cee441623bb874ae2686e86316a11725c06
|
data/.tool-versions
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
ruby 3.
|
2
|
-
bundler 2.3.
|
1
|
+
ruby 3.1.3
|
2
|
+
bundler 2.3.17
|
data/README.md
CHANGED
@@ -22,6 +22,8 @@ This api generator requires that you follow the [representer pattern](http://nic
|
|
22
22
|
|
23
23
|
## Controller
|
24
24
|
|
25
|
+
betterdocs comes with a DSL for the (Rails) controllers - see examples below.
|
26
|
+
|
25
27
|
```ruby
|
26
28
|
class ThingsController < ApplicationController
|
27
29
|
# :nocov: Documentation
|
@@ -99,6 +101,7 @@ module ThingsRepresenter
|
|
99
101
|
example 'my_name'
|
100
102
|
end
|
101
103
|
|
104
|
+
# Add a link to the links list in the resulting JSON.
|
102
105
|
link :self do
|
103
106
|
description to <<-end
|
104
107
|
Link to this resource itself
|
@@ -109,6 +112,12 @@ module ThingsRepresenter
|
|
109
112
|
end
|
110
113
|
```
|
111
114
|
|
115
|
+
GENERATING
|
116
|
+
----------
|
117
|
+
|
118
|
+
`rake doc:api:push` will push the documentation onto a git branch.
|
119
|
+
`rake doc:api:swagger` will call Swagger.
|
120
|
+
|
112
121
|
RELEASING
|
113
122
|
---------
|
114
123
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
data/betterdocs.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterdocs 0.
|
2
|
+
# stub: betterdocs 0.11.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "betterdocs".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.11.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["betterplace Developers".freeze]
|
11
|
-
s.date = "2022-07
|
11
|
+
s.date = "2022-12-07"
|
12
12
|
s.description = "This library provides tools to generate API documention for a web site's REST-ful JSON API.".freeze
|
13
13
|
s.email = "developers@betterplace.org".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze, "lib/betterdocs.rb".freeze, "lib/betterdocs/controller_collector.rb".freeze, "lib/betterdocs/dsl.rb".freeze, "lib/betterdocs/dsl/common.rb".freeze, "lib/betterdocs/dsl/controller.rb".freeze, "lib/betterdocs/dsl/controller/action.rb".freeze, "lib/betterdocs/dsl/controller/action/param.rb".freeze, "lib/betterdocs/dsl/controller/action/response.rb".freeze, "lib/betterdocs/dsl/controller/controller.rb".freeze, "lib/betterdocs/dsl/controller/controller_base.rb".freeze, "lib/betterdocs/dsl/json_params.rb".freeze, "lib/betterdocs/dsl/json_params/param.rb".freeze, "lib/betterdocs/dsl/json_type_mapper.rb".freeze, "lib/betterdocs/dsl/naming.rb".freeze, "lib/betterdocs/dsl/representer.rb".freeze, "lib/betterdocs/dsl/result.rb".freeze, "lib/betterdocs/dsl/result/collection_property.rb".freeze, "lib/betterdocs/dsl/result/link.rb".freeze, "lib/betterdocs/dsl/result/property.rb".freeze, "lib/betterdocs/generator/config_shortcuts.rb".freeze, "lib/betterdocs/generator/markdown.rb".freeze, "lib/betterdocs/generator/swagger.rb".freeze, "lib/betterdocs/global.rb".freeze, "lib/betterdocs/json_params_representer.rb".freeze, "lib/betterdocs/json_params_representer_collector.rb".freeze, "lib/betterdocs/json_time_with_zone.rb".freeze, "lib/betterdocs/mix_into_controller.rb".freeze, "lib/betterdocs/railtie.rb".freeze, "lib/betterdocs/rake_tasks.rb".freeze, "lib/betterdocs/representer.rb".freeze, "lib/betterdocs/result_representer.rb".freeze, "lib/betterdocs/result_representer_collector.rb".freeze, "lib/betterdocs/sanitizer.rb".freeze, "lib/betterdocs/section.rb".freeze, "lib/betterdocs/version.rb".freeze]
|
15
15
|
s.files = [".codeclimate.yml".freeze, ".gitignore".freeze, ".rspec".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, ".vscode/settings.json".freeze, "COPYING".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "betterdocs.gemspec".freeze, "lib/betterdocs.rb".freeze, "lib/betterdocs/controller_collector.rb".freeze, "lib/betterdocs/dsl.rb".freeze, "lib/betterdocs/dsl/common.rb".freeze, "lib/betterdocs/dsl/controller.rb".freeze, "lib/betterdocs/dsl/controller/action.rb".freeze, "lib/betterdocs/dsl/controller/action/param.rb".freeze, "lib/betterdocs/dsl/controller/action/response.rb".freeze, "lib/betterdocs/dsl/controller/controller.rb".freeze, "lib/betterdocs/dsl/controller/controller_base.rb".freeze, "lib/betterdocs/dsl/json_params.rb".freeze, "lib/betterdocs/dsl/json_params/param.rb".freeze, "lib/betterdocs/dsl/json_type_mapper.rb".freeze, "lib/betterdocs/dsl/naming.rb".freeze, "lib/betterdocs/dsl/representer.rb".freeze, "lib/betterdocs/dsl/result.rb".freeze, "lib/betterdocs/dsl/result/collection_property.rb".freeze, "lib/betterdocs/dsl/result/link.rb".freeze, "lib/betterdocs/dsl/result/property.rb".freeze, "lib/betterdocs/generator/config_shortcuts.rb".freeze, "lib/betterdocs/generator/markdown.rb".freeze, "lib/betterdocs/generator/markdown/templates/README.md.erb".freeze, "lib/betterdocs/generator/markdown/templates/section.md.erb".freeze, "lib/betterdocs/generator/swagger.rb".freeze, "lib/betterdocs/generator/swagger_static/index.html".freeze, "lib/betterdocs/global.rb".freeze, "lib/betterdocs/json_params_representer.rb".freeze, "lib/betterdocs/json_params_representer_collector.rb".freeze, "lib/betterdocs/json_time_with_zone.rb".freeze, "lib/betterdocs/mix_into_controller.rb".freeze, "lib/betterdocs/railtie.rb".freeze, "lib/betterdocs/rake_tasks.rb".freeze, "lib/betterdocs/representer.rb".freeze, "lib/betterdocs/result_representer.rb".freeze, "lib/betterdocs/result_representer_collector.rb".freeze, "lib/betterdocs/sanitizer.rb".freeze, "lib/betterdocs/section.rb".freeze, "lib/betterdocs/tasks/doc.rake".freeze, "lib/betterdocs/version.rb".freeze, "spec/assets/app/assets/images/logos/logo.png".freeze, "spec/assets/app/controllers/api/foos_controller.rb".freeze, "spec/assets/app/views/api_v4/documentation/assets/CHANGELOG.md".freeze, "spec/assets/config/betterdocs.yml".freeze, "spec/betterdocs/dsl/controller/action/param_spec.rb".freeze, "spec/betterdocs/dsl/controller/action/response_spec.rb".freeze, "spec/betterdocs/dsl/json_type_mapper_spec.rb".freeze, "spec/betterdocs/dsl/result/collection_property_spec.rb".freeze, "spec/betterdocs/dsl/result/link_spec.rb".freeze, "spec/betterdocs/dsl/result/property_spec.rb".freeze, "spec/betterdocs/generator/markdown_spec.rb".freeze, "spec/betterdocs/global_spec.rb".freeze, "spec/betterdocs/json_params_representer_spec.rb".freeze, "spec/betterdocs/result_representer_spec.rb".freeze, "spec/betterdocs/sanitizer_spec.rb".freeze, "spec/controller_dsl_spec.rb".freeze, "spec/result_representer_dsl_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
16
16
|
s.homepage = "https://github.com/betterplace/betterdocs".freeze
|
17
17
|
s.rdoc_options = ["--title".freeze, "Betterdocs".freeze, "--main".freeze, "README.md".freeze]
|
18
|
-
s.rubygems_version = "3.3.
|
18
|
+
s.rubygems_version = "3.3.26".freeze
|
19
19
|
s.summary = "Betterplace API documentation library".freeze
|
20
20
|
s.test_files = ["spec/assets/app/controllers/api/foos_controller.rb".freeze, "spec/betterdocs/dsl/controller/action/param_spec.rb".freeze, "spec/betterdocs/dsl/controller/action/response_spec.rb".freeze, "spec/betterdocs/dsl/json_type_mapper_spec.rb".freeze, "spec/betterdocs/dsl/result/collection_property_spec.rb".freeze, "spec/betterdocs/dsl/result/link_spec.rb".freeze, "spec/betterdocs/dsl/result/property_spec.rb".freeze, "spec/betterdocs/generator/markdown_spec.rb".freeze, "spec/betterdocs/global_spec.rb".freeze, "spec/betterdocs/json_params_representer_spec.rb".freeze, "spec/betterdocs/result_representer_spec.rb".freeze, "spec/betterdocs/sanitizer_spec.rb".freeze, "spec/controller_dsl_spec.rb".freeze, "spec/result_representer_dsl_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
21
21
|
|
@@ -17,8 +17,12 @@ class Betterdocs::Dsl::Controller::Action::Response
|
|
17
17
|
|
18
18
|
def data
|
19
19
|
@data ||= instance_eval(&@data_block)
|
20
|
+
if hash = @data.ask_and_send(:to_hash)
|
21
|
+
hash[:data].present? or raise Error, "result for #{controller}##{action} is empty"
|
22
|
+
end
|
23
|
+
@data
|
20
24
|
rescue => e
|
21
|
-
error = Error.new("#{e.class}: #{e}")
|
25
|
+
error = e.is_a?(Error) ? e : Error.new("#{e.class}: #{e}")
|
22
26
|
error.set_backtrace e.backtrace.grep(/^#{Betterdocs.rails.root}/)
|
23
27
|
raise error
|
24
28
|
end
|
@@ -102,7 +102,7 @@ module Betterdocs
|
|
102
102
|
|
103
103
|
def render_to(filename, template, binding)
|
104
104
|
File.open(filename, 'w') do |output|
|
105
|
-
rendered = ERB.new(template,
|
105
|
+
rendered = ERB.new(template, trim_mode: '-').result(binding)
|
106
106
|
output.write rendered
|
107
107
|
end
|
108
108
|
self
|
data/lib/betterdocs/version.rb
CHANGED
@@ -17,15 +17,18 @@ describe Betterdocs::Dsl::Controller::Action::Response do
|
|
17
17
|
double(
|
18
18
|
'Result',
|
19
19
|
representer: representer,
|
20
|
-
|
20
|
+
to_hash: { data: %w[ fake-it ] }
|
21
21
|
)
|
22
22
|
end
|
23
23
|
|
24
24
|
let :response do
|
25
25
|
data = result_data
|
26
|
-
described_class.new do
|
26
|
+
object = described_class.new do
|
27
27
|
data
|
28
28
|
end
|
29
|
+
allow(object).to receive(:controller).and_return('TheController')
|
30
|
+
allow(object).to receive(:action).and_return('in_action')
|
31
|
+
object
|
29
32
|
end
|
30
33
|
|
31
34
|
let :param_value do
|
@@ -37,6 +40,11 @@ describe Betterdocs::Dsl::Controller::Action::Response do
|
|
37
40
|
expect(response.params[:test]).to eq 'foo'
|
38
41
|
end
|
39
42
|
|
43
|
+
it 'complains about missing data in example responses' do
|
44
|
+
allow(result_data).to receive(:to_hash).and_return('data' => [])
|
45
|
+
expect { response.data }.to raise_error(Betterdocs::Dsl::Controller::Action::Response::Error)
|
46
|
+
end
|
47
|
+
|
40
48
|
it 'has data' do
|
41
49
|
expect(response.data).to eq result_data
|
42
50
|
end
|
@@ -54,6 +62,6 @@ describe Betterdocs::Dsl::Controller::Action::Response do
|
|
54
62
|
end
|
55
63
|
|
56
64
|
it 'can be converted into a JSON document' do
|
57
|
-
expect(response.to_json).to eq
|
65
|
+
expect(JSON(response.to_json)).to eq("data" => %w[ fake-it ])
|
58
66
|
end
|
59
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -297,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
297
297
|
- !ruby/object:Gem::Version
|
298
298
|
version: '0'
|
299
299
|
requirements: []
|
300
|
-
rubygems_version: 3.3.
|
300
|
+
rubygems_version: 3.3.26
|
301
301
|
signing_key:
|
302
302
|
specification_version: 4
|
303
303
|
summary: Betterplace API documentation library
|