rspec-api-docs 0.1.0 → 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/.gitignore +2 -0
- data/.rubocop.yml +55 -0
- data/README.md +222 -4
- data/Rakefile +9 -2
- data/bin/generate_integration_docs +14 -0
- data/lib/rspec_api_docs.rb +2 -16
- data/lib/rspec_api_docs/after.rb +20 -3
- data/lib/rspec_api_docs/after/type_checker.rb +56 -0
- data/lib/rspec_api_docs/config.rb +27 -0
- data/lib/rspec_api_docs/dsl.rb +35 -10
- data/lib/rspec_api_docs/dsl/doc_proxy.rb +71 -0
- data/lib/rspec_api_docs/dsl/request_store.rb +21 -0
- data/lib/rspec_api_docs/formatter.rb +44 -6
- data/lib/rspec_api_docs/formatter/renderer/json_renderer.rb +35 -0
- data/lib/rspec_api_docs/formatter/renderer/json_renderer/example_serializer.rb +47 -0
- data/lib/rspec_api_docs/formatter/renderer/json_renderer/name.rb +18 -0
- data/lib/rspec_api_docs/formatter/renderer/json_renderer/resource_serializer.rb +31 -0
- data/lib/rspec_api_docs/formatter/renderer/raddocs_renderer.rb +56 -0
- data/lib/rspec_api_docs/formatter/renderer/raddocs_renderer/index_serializer.rb +57 -0
- data/lib/rspec_api_docs/formatter/renderer/raddocs_renderer/link.rb +11 -0
- data/lib/rspec_api_docs/formatter/renderer/raddocs_renderer/resource_serializer.rb +58 -0
- data/lib/rspec_api_docs/formatter/renderer/slate_renderer.rb +29 -0
- data/lib/rspec_api_docs/formatter/renderer/slate_renderer/slate_index.html.md.erb +45 -0
- data/lib/rspec_api_docs/formatter/resource.rb +25 -111
- data/lib/rspec_api_docs/formatter/resource/example.rb +125 -0
- data/lib/rspec_api_docs/formatter/resource/parameter.rb +39 -0
- data/lib/rspec_api_docs/formatter/resource/response_field.rb +39 -0
- data/lib/rspec_api_docs/version.rb +1 -1
- data/rspec-api-docs.gemspec +1 -0
- metadata +34 -5
- data/lib/rspec_api_docs/formatter/index_serializer.rb +0 -37
- data/lib/rspec_api_docs/formatter/renderers/json_renderer.rb +0 -34
- data/lib/rspec_api_docs/formatter/resource_serializer.rb +0 -21
@@ -0,0 +1,39 @@
|
|
1
|
+
module RspecApiDocs
|
2
|
+
class Resource
|
3
|
+
class Parameter
|
4
|
+
attr_reader :name, :parameter
|
5
|
+
|
6
|
+
def initialize(name, parameter)
|
7
|
+
@name = name
|
8
|
+
@parameter = parameter
|
9
|
+
end
|
10
|
+
|
11
|
+
# The scope of the parameter
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
def scope
|
15
|
+
parameter[:scope].join
|
16
|
+
end
|
17
|
+
|
18
|
+
# If the parameter is required
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def required
|
22
|
+
!!parameter[:required]
|
23
|
+
end
|
24
|
+
|
25
|
+
# The description of the parameter
|
26
|
+
#
|
27
|
+
# @return [String]
|
28
|
+
def description
|
29
|
+
parameter[:description]
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [true, false]
|
33
|
+
def ==(other)
|
34
|
+
name == other.name &&
|
35
|
+
parameter == other.parameter
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RspecApiDocs
|
2
|
+
class Resource
|
3
|
+
class ResponseField
|
4
|
+
attr_reader :name, :field
|
5
|
+
|
6
|
+
def initialize(name, field)
|
7
|
+
@name = name
|
8
|
+
@field = field
|
9
|
+
end
|
10
|
+
|
11
|
+
# The scope of the response field
|
12
|
+
#
|
13
|
+
# @return [String]
|
14
|
+
def scope
|
15
|
+
field[:scope].join
|
16
|
+
end
|
17
|
+
|
18
|
+
# The type of the response field
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def type
|
22
|
+
field[:type]
|
23
|
+
end
|
24
|
+
|
25
|
+
# The description of the response field
|
26
|
+
#
|
27
|
+
# @return [String]
|
28
|
+
def description
|
29
|
+
field[:description]
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [true, false]
|
33
|
+
def ==(other)
|
34
|
+
name == other.name &&
|
35
|
+
field == other.field
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/rspec-api-docs.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-api-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Odin Dutton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,33 +108,62 @@ dependencies:
|
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 2.0.0.beta2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description:
|
112
126
|
email:
|
113
127
|
- odindutton@gmail.com
|
114
128
|
executables:
|
129
|
+
- generate_integration_docs
|
115
130
|
- setup
|
116
131
|
extensions: []
|
117
132
|
extra_rdoc_files: []
|
118
133
|
files:
|
119
134
|
- ".gitignore"
|
120
135
|
- ".rspec"
|
136
|
+
- ".rubocop.yml"
|
121
137
|
- ".travis.yml"
|
122
138
|
- CODE_OF_CONDUCT.md
|
123
139
|
- Gemfile
|
124
140
|
- LICENSE.txt
|
125
141
|
- README.md
|
126
142
|
- Rakefile
|
143
|
+
- bin/generate_integration_docs
|
127
144
|
- bin/setup
|
128
145
|
- lib/rspec_api_docs.rb
|
129
146
|
- lib/rspec_api_docs/after.rb
|
147
|
+
- lib/rspec_api_docs/after/type_checker.rb
|
148
|
+
- lib/rspec_api_docs/config.rb
|
130
149
|
- lib/rspec_api_docs/dsl.rb
|
131
150
|
- lib/rspec_api_docs/dsl/doc_proxy.rb
|
132
151
|
- lib/rspec_api_docs/dsl/request_store.rb
|
133
152
|
- lib/rspec_api_docs/formatter.rb
|
134
|
-
- lib/rspec_api_docs/formatter/
|
135
|
-
- lib/rspec_api_docs/formatter/
|
153
|
+
- lib/rspec_api_docs/formatter/renderer/json_renderer.rb
|
154
|
+
- lib/rspec_api_docs/formatter/renderer/json_renderer/example_serializer.rb
|
155
|
+
- lib/rspec_api_docs/formatter/renderer/json_renderer/name.rb
|
156
|
+
- lib/rspec_api_docs/formatter/renderer/json_renderer/resource_serializer.rb
|
157
|
+
- lib/rspec_api_docs/formatter/renderer/raddocs_renderer.rb
|
158
|
+
- lib/rspec_api_docs/formatter/renderer/raddocs_renderer/index_serializer.rb
|
159
|
+
- lib/rspec_api_docs/formatter/renderer/raddocs_renderer/link.rb
|
160
|
+
- lib/rspec_api_docs/formatter/renderer/raddocs_renderer/resource_serializer.rb
|
161
|
+
- lib/rspec_api_docs/formatter/renderer/slate_renderer.rb
|
162
|
+
- lib/rspec_api_docs/formatter/renderer/slate_renderer/slate_index.html.md.erb
|
136
163
|
- lib/rspec_api_docs/formatter/resource.rb
|
137
|
-
- lib/rspec_api_docs/formatter/
|
164
|
+
- lib/rspec_api_docs/formatter/resource/example.rb
|
165
|
+
- lib/rspec_api_docs/formatter/resource/parameter.rb
|
166
|
+
- lib/rspec_api_docs/formatter/resource/response_field.rb
|
138
167
|
- lib/rspec_api_docs/version.rb
|
139
168
|
- rspec-api-docs.gemspec
|
140
169
|
homepage: https://github.com/twe4ked
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class IndexSerializer
|
2
|
-
class ResourceSerializer
|
3
|
-
attr_reader :resource
|
4
|
-
|
5
|
-
def initialize(resource)
|
6
|
-
@resource = resource
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_h
|
10
|
-
{
|
11
|
-
description: resource.example_name,
|
12
|
-
link: resource.link,
|
13
|
-
groups: resource.groups,
|
14
|
-
route: resource.path,
|
15
|
-
method: resource.http_method.downcase,
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :resources
|
21
|
-
|
22
|
-
def initialize(resources)
|
23
|
-
@resources = resources.group_by(&:name)
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_h
|
27
|
-
{
|
28
|
-
resources: resources.map do |name, examples|
|
29
|
-
{
|
30
|
-
name: name,
|
31
|
-
explanation: nil,
|
32
|
-
examples: examples.map { |resource| ResourceSerializer.new(resource).to_h },
|
33
|
-
}
|
34
|
-
end
|
35
|
-
}
|
36
|
-
end
|
37
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rspec_api_docs/formatter/index_serializer'
|
2
|
-
require 'rspec_api_docs/formatter/resource_serializer'
|
3
|
-
|
4
|
-
module RspecApiDocs
|
5
|
-
class JSONRender
|
6
|
-
attr_reader :resources
|
7
|
-
|
8
|
-
def initialize(resources)
|
9
|
-
@resources = resources
|
10
|
-
end
|
11
|
-
|
12
|
-
def render
|
13
|
-
FileUtils.mkdir_p output_dir
|
14
|
-
|
15
|
-
File.open(output_dir + 'index.json', 'w') do |f|
|
16
|
-
f.write JSON.pretty_generate(IndexSerializer.new(resources).to_h) + "\n"
|
17
|
-
end
|
18
|
-
|
19
|
-
resources.each do |resource|
|
20
|
-
FileUtils.mkdir_p output_dir + Pathname.new(resource.link).dirname
|
21
|
-
|
22
|
-
File.open(output_dir + resource.link, 'w') do |f|
|
23
|
-
f.write JSON.pretty_generate(ResourceSerializer.new(resource).to_h) + "\n"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def output_dir
|
31
|
-
Pathname.new RspecApiDocs.configuration.output_dir
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class ResourceSerializer
|
2
|
-
attr_reader :resource
|
3
|
-
|
4
|
-
def initialize(resource)
|
5
|
-
@resource = resource
|
6
|
-
end
|
7
|
-
|
8
|
-
def to_h
|
9
|
-
{
|
10
|
-
resource: resource.name,
|
11
|
-
resource_explanation: nil,
|
12
|
-
http_method: resource.http_method,
|
13
|
-
route: resource.path,
|
14
|
-
description: resource.example_name,
|
15
|
-
explanation: resource.description,
|
16
|
-
parameters: resource.parameters,
|
17
|
-
response_fields: resource.response_fields,
|
18
|
-
requests: resource.requests,
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|