grape_doc 0.1.0 → 0.2.0
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 +7 -0
- data/.rvmrc +1 -1
- data/LICENSE +2 -2
- data/grape_doc.gemspec +8 -2
- data/lib/grape_doc/api_parameter.rb +4 -1
- data/lib/grape_doc/formatters/markdown_formatter.rb +12 -5
- data/lib/grape_doc/version.rb +1 -1
- data/lib/grape_doc.rb +0 -6
- data/spec/api_document_spec.rb +6 -6
- data/spec/api_parameter_spec.rb +8 -8
- data/spec/api_parser_spec.rb +27 -27
- data/spec/api_resource_spec.rb +1 -1
- data/spec/api_response.rb +2 -1
- data/spec/doc_generator_spec.rb +2 -2
- data/spec/markdown_formatter_spec.rb +41 -0
- metadata +19 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c0dd09087124eaa66fffeb08428b7b076177852
|
4
|
+
data.tar.gz: 14c3153746fa290afccc1816637f2c68827a40df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0fe1235aa18f280205715d7565707b2037086fe5a6477c9ae3ff4abcccc8385fc2b55495085579c01eb0c2b1cab101881dadaa1f09b9d3038ea5076809e36c67
|
7
|
+
data.tar.gz: dace415def09bb94d69adb8052e940c2a1d1381ddd986ef0bb82e64f5c08f89ceb06ba45c98b3d93502a02fe886165eff70b7c94725df1bb12ea40fdd1aea77a
|
data/.rvmrc
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
7
|
# Only full ruby name is supported here, for short names use:
|
8
8
|
# echo "rvm use 1.9.2" > .rvmrc
|
9
|
-
environment_id="ruby-1.9.
|
9
|
+
environment_id="ruby-1.9.3-p484@grape_doc"
|
10
10
|
|
11
11
|
# Uncomment the following lines if you want to verify rvm version per project
|
12
12
|
# rvmrc_rvm_version="1.13.6 (stable)" # 1.10.1 seams as a safe start
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2015 Alex Denisov
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/grape_doc.gemspec
CHANGED
@@ -2,8 +2,14 @@
|
|
2
2
|
require File.expand_path('../lib/grape_doc/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Alex Denisov"
|
6
|
-
|
5
|
+
gem.authors = ["Alex Denisov",
|
6
|
+
"rayko",
|
7
|
+
"Jack Forrest",
|
8
|
+
"Chelsea Robb"]
|
9
|
+
gem.email = ["1101.debian@gmail.com",
|
10
|
+
"rayko.drg@gmail.com",
|
11
|
+
"jack@jrforrest.net",
|
12
|
+
"chelsea.robb@gmail.com"]
|
7
13
|
gem.description = %q{Documentation generator for Grape API}
|
8
14
|
gem.summary = %q{Documentation generator for Grape API}
|
9
15
|
gem.homepage = "https://github.com/AlexDenisov/grape_doc"
|
@@ -16,6 +16,10 @@ module GrapeDoc
|
|
16
16
|
parameter_hash[:required]
|
17
17
|
self.description = parameter_hash[:desc] ||
|
18
18
|
parameter_hash[:description]
|
19
|
+
self.field_type = parameter_hash[:type]
|
20
|
+
if parameter_hash.keys.include? :documentation
|
21
|
+
self.sample_value = parameter_hash[:documentation][:example]
|
22
|
+
end
|
19
23
|
end
|
20
24
|
def self.initialize_parameters(params_hash)
|
21
25
|
params = params_hash.map do |name, hash|
|
@@ -26,4 +30,3 @@ module GrapeDoc
|
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
29
|
-
|
@@ -4,15 +4,17 @@ module GrapeDoc
|
|
4
4
|
title = "### #{resource.resource_name}\n"
|
5
5
|
|
6
6
|
documents = resource.documents.map do |document|
|
7
|
-
path = "#### #{document.http_method} #{document.path}\n\n"
|
7
|
+
path = "#### #{document.http_method} #{escape(document.path)}\n\n"
|
8
8
|
description = "#{document.description}\n\n"
|
9
9
|
|
10
10
|
parameters = document.params.map do |parameter|
|
11
11
|
next if parameter.field.nil? or parameter.field.empty?
|
12
|
-
param = " - #{parameter.field}"
|
12
|
+
param = " - #{escape(parameter.field)}"
|
13
13
|
param += " (#{parameter.field_type})" if parameter.field_type
|
14
|
-
param += " (required)" if parameter.required
|
15
|
-
param += " : #{parameter.description}
|
14
|
+
param += " (*required*)" if parameter.required
|
15
|
+
param += " : #{parameter.description} " if parameter.description
|
16
|
+
param += " Example: #{parameter.sample_value}" if parameter.sample_value
|
17
|
+
param += "\n\n"
|
16
18
|
end.join if document.params
|
17
19
|
|
18
20
|
route = "#{path} #{description}"
|
@@ -23,6 +25,11 @@ module GrapeDoc
|
|
23
25
|
return "" if documents.nil? or documents.empty?
|
24
26
|
"#{title}\n\n\n#{documents}\n"
|
25
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def escape(str)
|
32
|
+
str.gsub('_', '\_')
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
28
|
-
|
data/lib/grape_doc/version.rb
CHANGED
data/lib/grape_doc.rb
CHANGED
@@ -8,12 +8,6 @@ require 'grape_doc/doc_generator'
|
|
8
8
|
require 'grape_doc/formatters/markdown_formatter'
|
9
9
|
require 'trollop'
|
10
10
|
|
11
|
-
#begin
|
12
|
-
#require File.expand_path(Dir.pwd + "/config/environment")
|
13
|
-
#rescue LoadError => ex
|
14
|
-
# puts "#{ex}"
|
15
|
-
#end
|
16
|
-
|
17
11
|
module GrapeDoc
|
18
12
|
def self.generate_doc
|
19
13
|
opts = Trollop::options do
|
data/spec/api_document_spec.rb
CHANGED
@@ -6,22 +6,22 @@ describe "GrapeDoc::APIDocument" do
|
|
6
6
|
GrapeDoc::APIDocument.new
|
7
7
|
}
|
8
8
|
it "resource" do
|
9
|
-
api_document.respond_to?(:resource_name).
|
9
|
+
expect(api_document.respond_to?(:resource_name)).to eq(true)
|
10
10
|
end
|
11
11
|
it "path" do
|
12
|
-
api_document.respond_to?(:path).
|
12
|
+
expect(api_document.respond_to?(:path)).to eq(true)
|
13
13
|
end
|
14
14
|
it "description" do
|
15
|
-
api_document.respond_to?(:description).
|
15
|
+
expect(api_document.respond_to?(:description)).to eq(true)
|
16
16
|
end
|
17
17
|
it "params" do
|
18
|
-
api_document.respond_to?(:params).
|
18
|
+
expect(api_document.respond_to?(:params)).to eq(true)
|
19
19
|
end
|
20
20
|
it "response" do
|
21
|
-
api_document.respond_to?(:response).
|
21
|
+
expect(api_document.respond_to?(:response)).to eq(true)
|
22
22
|
end
|
23
23
|
it "http_method" do
|
24
|
-
api_document.respond_to?(:http_method).
|
24
|
+
expect(api_document.respond_to?(:http_method)).to eq(true)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/spec/api_parameter_spec.rb
CHANGED
@@ -9,16 +9,16 @@ describe GrapeDoc::APIParameter do
|
|
9
9
|
|
10
10
|
describe "should respond to" do
|
11
11
|
it "field" do
|
12
|
-
parameter.respond_to?(:field).
|
12
|
+
expect(parameter.respond_to?(:field)).to eq(true)
|
13
13
|
end
|
14
14
|
it "description" do
|
15
|
-
parameter.respond_to?(:description).
|
15
|
+
expect(parameter.respond_to?(:description)).to eq(true)
|
16
16
|
end
|
17
17
|
it "sample_value" do
|
18
|
-
parameter.respond_to?(:sample_value).
|
18
|
+
expect(parameter.respond_to?(:sample_value)).to eq(true)
|
19
19
|
end
|
20
20
|
it "field_type" do
|
21
|
-
parameter.respond_to?(:field_type).
|
21
|
+
expect(parameter.respond_to?(:field_type)).to eq(true)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,15 +27,15 @@ describe GrapeDoc::APIParameter do
|
|
27
27
|
document = parser.parse(Projects)[2]
|
28
28
|
params = document.params
|
29
29
|
params.each do |p|
|
30
|
-
p.kind_of?(APIParameter).
|
30
|
+
expect(p.kind_of?(APIParameter)).to eq(true)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
it "parse PUT project with parameters" do
|
34
34
|
document = parser.parse(Projects)[2]
|
35
35
|
param = document.params.first
|
36
|
-
param.field.
|
37
|
-
param.description.
|
38
|
-
param.required.
|
36
|
+
expect(param.field).to eq("project_id")
|
37
|
+
expect(param.description).to eq("Project ID")
|
38
|
+
expect(param.required).to eq(true)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/spec/api_parser_spec.rb
CHANGED
@@ -8,38 +8,38 @@ describe GrapeDoc::APIParser do
|
|
8
8
|
let(:parser) { APIParser.new }
|
9
9
|
describe "parse empty child class" do
|
10
10
|
it "should return nil" do
|
11
|
-
parser.parse(Users).
|
11
|
+
expect(parser.parse(Users)).to eq(nil)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
describe "parse non-empty child class" do
|
15
15
|
it "should_not return nil" do
|
16
|
-
parser.parse(Projects).
|
16
|
+
expect(parser.parse(Projects)).not_to eq(nil)
|
17
17
|
end
|
18
18
|
it "should return two documents" do
|
19
|
-
parser.parse(Projects).count.
|
19
|
+
expect(parser.parse(Projects).count).to eq(4)
|
20
20
|
end
|
21
21
|
it "should return array of APIDocument objects" do
|
22
22
|
parser.parse(Projects).each do |document|
|
23
|
-
document.kind_of?(APIDocument).
|
23
|
+
expect(document.kind_of?(APIDocument)).to eq(true)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
it "should parse GET route without meta info" do
|
27
27
|
document = parser.parse(Projects).first
|
28
|
-
document.resource_name.
|
29
|
-
document.path.
|
30
|
-
document.http_method.
|
31
|
-
document.description.
|
32
|
-
document.params.
|
33
|
-
document.response.
|
28
|
+
expect(document.resource_name).to eq("Projects")
|
29
|
+
expect(document.path).to eq("/projects")
|
30
|
+
expect(document.http_method).to eq( "GET")
|
31
|
+
expect(document.description).to eq(nil)
|
32
|
+
expect(document.params).to eq(nil)
|
33
|
+
expect(document.response).to eq(nil)
|
34
34
|
end
|
35
35
|
it "should parse POST route within meta info" do
|
36
36
|
document = parser.parse(Projects)[1]
|
37
|
-
document.resource_name.
|
38
|
-
document.path.
|
39
|
-
document.http_method.
|
40
|
-
document.description.
|
41
|
-
document.params.
|
42
|
-
document.response.
|
37
|
+
expect(document.resource_name).to eq("Projects")
|
38
|
+
expect(document.path).to eq("/projects")
|
39
|
+
expect(document.http_method).to eq("POST")
|
40
|
+
expect(document.description).to eq("Create Project")
|
41
|
+
expect(document.params).to eq(nil)
|
42
|
+
expect(document.response).to eq(nil)
|
43
43
|
end
|
44
44
|
it "should parse PUT route within meta info" do
|
45
45
|
params = {
|
@@ -49,11 +49,11 @@ describe GrapeDoc::APIParser do
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
document = parser.parse(Projects)[2]
|
52
|
-
document.resource_name.
|
53
|
-
document.path.
|
54
|
-
document.http_method.
|
55
|
-
document.description.
|
56
|
-
document.response.
|
52
|
+
expect(document.resource_name).to eq("Projects")
|
53
|
+
expect(document.path).to eq("/projects")
|
54
|
+
expect(document.http_method).to eq("PUT")
|
55
|
+
expect(document.description).to eq("Update Project")
|
56
|
+
expect(document.response).to eq(nil)
|
57
57
|
end
|
58
58
|
it "should parse DELETE route within meta info" do
|
59
59
|
params = {
|
@@ -66,12 +66,12 @@ describe GrapeDoc::APIParser do
|
|
66
66
|
:status => true
|
67
67
|
}
|
68
68
|
document = parser.parse(Projects)[3]
|
69
|
-
document.resource_name.
|
70
|
-
document.path.
|
71
|
-
document.http_method.
|
72
|
-
document.description.
|
73
|
-
#
|
74
|
-
document.response.
|
69
|
+
expect(document.resource_name).to eq("Projects")
|
70
|
+
expect(document.path).to eq("/projects")
|
71
|
+
expect(document.http_method).to eq("DELETE")
|
72
|
+
expect(document.description).to eq("Delete Project")
|
73
|
+
# expect(document.params).to eq(params)
|
74
|
+
expect(document.response).to eq(response)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/spec/api_resource_spec.rb
CHANGED
data/spec/api_response.rb
CHANGED
data/spec/doc_generator_spec.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'GrapeDoc::MarkdownFormatter' do
|
4
|
+
let(:formatter) { GrapeDoc::MarkdownFormatter.new }
|
5
|
+
|
6
|
+
let(:resource) do
|
7
|
+
instance_double('GrapeDoc::APIResource',
|
8
|
+
resource_name: 'MightyNeatResource',
|
9
|
+
documents: [document])
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:param) do
|
13
|
+
instance_double('GrapeDoc::APIParameter',
|
14
|
+
field: 'radical_value',
|
15
|
+
field_type: 'String',
|
16
|
+
required: true,
|
17
|
+
description: 'This value is so very rad. I bet you wish you were too.',
|
18
|
+
sample_value: 'raddish')
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:document) do
|
22
|
+
instance_double('GrapeDoc::APIDocument',
|
23
|
+
params: [param],
|
24
|
+
http_method: 'POST',
|
25
|
+
path: '/a_twisty_path',
|
26
|
+
description: 'Nobody really knows what this does.'\
|
27
|
+
'Nobody but Zorp that is.')
|
28
|
+
end
|
29
|
+
|
30
|
+
subject(:markdown) { formatter.generate_resource_doc(resource) }
|
31
|
+
|
32
|
+
it 'escapes underscores in paths' do
|
33
|
+
expect(markdown).not_to match /\/a_twisty_path/
|
34
|
+
expect(markdown).to match /\/a\\_twisty\\_path/
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'escapes underscores in param names' do
|
38
|
+
expect(markdown).not_to match /radical_value/
|
39
|
+
expect(markdown).to match /radical\\_value/
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,42 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alex Denisov
|
8
|
+
- rayko
|
9
|
+
- Jack Forrest
|
10
|
+
- Chelsea Robb
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: grape
|
16
18
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: '0.2'
|
22
|
-
- -
|
23
|
+
- - '>='
|
23
24
|
- !ruby/object:Gem::Version
|
24
25
|
version: 0.2.1
|
25
26
|
type: :runtime
|
26
27
|
prerelease: false
|
27
28
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '0.2'
|
33
|
-
- -
|
33
|
+
- - '>='
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: 0.2.1
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: trollop
|
38
38
|
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
39
|
requirements:
|
41
40
|
- - ~>
|
42
41
|
- !ruby/object:Gem::Version
|
@@ -44,7 +43,6 @@ dependencies:
|
|
44
43
|
type: :runtime
|
45
44
|
prerelease: false
|
46
45
|
version_requirements: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
46
|
requirements:
|
49
47
|
- - ~>
|
50
48
|
- !ruby/object:Gem::Version
|
@@ -52,29 +50,26 @@ dependencies:
|
|
52
50
|
- !ruby/object:Gem::Dependency
|
53
51
|
name: json
|
54
52
|
requirement: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
53
|
requirements:
|
57
54
|
- - ~>
|
58
55
|
- !ruby/object:Gem::Version
|
59
56
|
version: '1.7'
|
60
|
-
- -
|
57
|
+
- - '>='
|
61
58
|
- !ruby/object:Gem::Version
|
62
59
|
version: 1.7.4
|
63
60
|
type: :runtime
|
64
61
|
prerelease: false
|
65
62
|
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
63
|
requirements:
|
68
64
|
- - ~>
|
69
65
|
- !ruby/object:Gem::Version
|
70
66
|
version: '1.7'
|
71
|
-
- -
|
67
|
+
- - '>='
|
72
68
|
- !ruby/object:Gem::Version
|
73
69
|
version: 1.7.4
|
74
70
|
- !ruby/object:Gem::Dependency
|
75
71
|
name: rspec
|
76
72
|
requirement: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
73
|
requirements:
|
79
74
|
- - ~>
|
80
75
|
- !ruby/object:Gem::Version
|
@@ -82,7 +77,6 @@ dependencies:
|
|
82
77
|
type: :development
|
83
78
|
prerelease: false
|
84
79
|
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
80
|
requirements:
|
87
81
|
- - ~>
|
88
82
|
- !ruby/object:Gem::Version
|
@@ -90,6 +84,9 @@ dependencies:
|
|
90
84
|
description: Documentation generator for Grape API
|
91
85
|
email:
|
92
86
|
- 1101.debian@gmail.com
|
87
|
+
- rayko.drg@gmail.com
|
88
|
+
- jack@jrforrest.net
|
89
|
+
- chelsea.robb@gmail.com
|
93
90
|
executables:
|
94
91
|
- grape_doc
|
95
92
|
extensions: []
|
@@ -119,33 +116,33 @@ files:
|
|
119
116
|
- spec/api_resource_spec.rb
|
120
117
|
- spec/api_response.rb
|
121
118
|
- spec/doc_generator_spec.rb
|
119
|
+
- spec/markdown_formatter_spec.rb
|
122
120
|
- spec/spec_helper.rb
|
123
121
|
- spec/test_classes/api.rb
|
124
122
|
- spec/test_classes/projects.rb
|
125
123
|
- spec/test_classes/users.rb
|
126
124
|
homepage: https://github.com/AlexDenisov/grape_doc
|
127
125
|
licenses: []
|
126
|
+
metadata: {}
|
128
127
|
post_install_message:
|
129
128
|
rdoc_options: []
|
130
129
|
require_paths:
|
131
130
|
- lib
|
132
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
132
|
requirements:
|
135
|
-
- -
|
133
|
+
- - '>='
|
136
134
|
- !ruby/object:Gem::Version
|
137
135
|
version: '0'
|
138
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
137
|
requirements:
|
141
|
-
- -
|
138
|
+
- - '>='
|
142
139
|
- !ruby/object:Gem::Version
|
143
140
|
version: '0'
|
144
141
|
requirements: []
|
145
142
|
rubyforge_project:
|
146
|
-
rubygems_version:
|
143
|
+
rubygems_version: 2.0.3
|
147
144
|
signing_key:
|
148
|
-
specification_version:
|
145
|
+
specification_version: 4
|
149
146
|
summary: Documentation generator for Grape API
|
150
147
|
test_files:
|
151
148
|
- spec/api_document_spec.rb
|
@@ -154,8 +151,8 @@ test_files:
|
|
154
151
|
- spec/api_resource_spec.rb
|
155
152
|
- spec/api_response.rb
|
156
153
|
- spec/doc_generator_spec.rb
|
154
|
+
- spec/markdown_formatter_spec.rb
|
157
155
|
- spec/spec_helper.rb
|
158
156
|
- spec/test_classes/api.rb
|
159
157
|
- spec/test_classes/projects.rb
|
160
158
|
- spec/test_classes/users.rb
|
161
|
-
has_rdoc:
|