fdoc 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.md +15 -0
  2. data/lib/fdoc.rb +2 -1
  3. data/lib/fdoc/cli.rb +53 -15
  4. data/lib/fdoc/meta_service.rb +1 -1
  5. data/lib/fdoc/presenters/{html_presenter.rb → base_presenter.rb} +12 -17
  6. data/lib/fdoc/presenters/endpoint_presenter.rb +22 -24
  7. data/lib/fdoc/presenters/json_presenter.rb +31 -0
  8. data/lib/fdoc/presenters/meta_service_presenter.rb +25 -6
  9. data/lib/fdoc/presenters/response_code_presenter.rb +13 -4
  10. data/lib/fdoc/presenters/schema_presenter.rb +36 -4
  11. data/lib/fdoc/presenters/service_presenter.rb +25 -6
  12. data/lib/fdoc/templates/endpoint.html.erb +5 -5
  13. data/lib/fdoc/templates/endpoint.md.erb +40 -0
  14. data/lib/fdoc/templates/meta_service.html.erb +3 -1
  15. data/lib/fdoc/templates/meta_service.md.erb +20 -0
  16. data/lib/fdoc/templates/service.html.erb +4 -2
  17. data/lib/fdoc/templates/service.md.erb +18 -0
  18. data/lib/fdoc/templates/shared/endpoint_name.html.erb +8 -0
  19. data/lib/fdoc/templates/shared/endpoint_name.md.erb +1 -0
  20. data/lib/fdoc/templates/styles.css +1 -1
  21. data/spec/fdoc/cli_spec.rb +87 -40
  22. data/spec/fdoc/endpoint_scaffold_spec.rb +5 -5
  23. data/spec/fdoc/endpoint_spec.rb +18 -18
  24. data/spec/fdoc/presenters/base_presenter_spec.rb +28 -0
  25. data/spec/fdoc/presenters/endpoint_presenter_spec.rb +8 -1
  26. data/spec/fdoc/presenters/meta_service_presenter_spec.rb +38 -0
  27. data/spec/fdoc/presenters/schema_presenter_spec.rb +34 -0
  28. data/spec/fdoc/presenters/service_presenter_spec.rb +24 -1
  29. data/spec/fixtures/members/list/complex-params-GET.fdoc +20 -20
  30. data/spec/spec_helper.rb +1 -0
  31. metadata +14 -2
@@ -81,9 +81,9 @@ describe Fdoc::EndpointScaffold do
81
81
  subject.request_parameters["properties"].should have_key "with_symbol"
82
82
  subject.request_parameters["properties"].should_not have_key :with_symbol
83
83
  subject.request_parameters["properties"].should have_key "with_string"
84
- subject.request_parameters["properties"].should_not have_key :with_string
84
+ subject.request_parameters["properties"].should_not have_key :with_string
85
85
  end
86
-
86
+
87
87
  it "uses strings (not symbols) for keys of nested hashes" do
88
88
  mixed_params = {
89
89
  "nested_object" => {
@@ -95,14 +95,14 @@ describe Fdoc::EndpointScaffold do
95
95
  subject.consume_request(mixed_params)
96
96
  subject.request_parameters["properties"]["nested_object"]["properties"].keys.sort.should == ["with_string", "with_symbol"]
97
97
  end
98
-
98
+
99
99
  it "uses strings (not symbols) for nested hashes inside arrays" do
100
100
  mixed_params = {
101
101
  "nested_array" => [
102
102
  {
103
103
  :with_symbol => false,
104
104
  "with_string" => true
105
- }
105
+ }
106
106
  ]
107
107
  }
108
108
 
@@ -214,7 +214,7 @@ describe Fdoc::EndpointScaffold do
214
214
  subject.response_parameters["properties"].should have_key "with_symbol"
215
215
  subject.response_parameters["properties"].should_not have_key :with_symbol
216
216
  subject.response_parameters["properties"].should have_key "with_string"
217
- subject.response_parameters["properties"].should_not have_key :with_string
217
+ subject.response_parameters["properties"].should_not have_key :with_string
218
218
  end
219
219
 
220
220
  it "produces a valid JSON schema for the response" do
@@ -5,7 +5,7 @@ describe Fdoc::Endpoint do
5
5
  let(:fdoc_fixture) { ["GET", "members/list"] }
6
6
  let (:test_service) { Fdoc::Service.new('spec/fixtures') }
7
7
  subject { endpoint }
8
-
8
+
9
9
  def remove_optional(obj)
10
10
  case obj
11
11
  when Hash
@@ -42,7 +42,7 @@ describe Fdoc::Endpoint do
42
42
  "order_by" => "name"
43
43
  }
44
44
  }
45
-
45
+
46
46
  context "with a well-behaved request" do
47
47
  it "returns true" do
48
48
  subject.should be_true
@@ -67,12 +67,12 @@ describe Fdoc::Endpoint do
67
67
 
68
68
  context "when the response encounters an object of an known type" do
69
69
  before { params.merge!("offset" => "woot") }
70
-
70
+
71
71
  it "should have the Ruby type in the error message" do
72
72
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /String/)
73
73
  end
74
74
  end
75
-
75
+
76
76
  context "complex examples" do
77
77
  let(:fdoc_fixture) { ["GET", "/members/list/complex-params"] }
78
78
  let(:params) {
@@ -83,7 +83,7 @@ describe Fdoc::Endpoint do
83
83
  "required_param" => "here",
84
84
  "optional_param" => "here"
85
85
  }
86
- ],
86
+ ],
87
87
  "required_nested_array" => [
88
88
  {
89
89
  "required_param" => "here",
@@ -93,7 +93,7 @@ describe Fdoc::Endpoint do
93
93
  "optional_param" => "here"
94
94
  }
95
95
  },
96
- ],
96
+ ],
97
97
  "optional_nested_object" => {
98
98
  "required_param" => "here",
99
99
  "optional_param" => "here"
@@ -108,30 +108,30 @@ describe Fdoc::Endpoint do
108
108
  },
109
109
  }
110
110
  }
111
-
111
+
112
112
  it "is successful" do
113
113
  subject.should be_true
114
114
  end
115
-
116
- context "with no optional keys" do
115
+
116
+ context "with no optional keys" do
117
117
  before { remove_optional(params) }
118
118
 
119
119
  it "does not contain optional keys" do
120
120
  params.keys.sort.should == ["required_nested_array", "required_nested_object", "toplevel_param"]
121
121
  end
122
-
122
+
123
123
  it "is successful" do
124
124
  subject.should be_true
125
- end
125
+ end
126
126
  end
127
-
127
+
128
128
  context "non documented field added" do
129
129
  before { params.merge!("non_documented" => true) }
130
130
  it "raises an error" do
131
131
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /non_documented/)
132
132
  end
133
133
  end
134
-
134
+
135
135
  context "non document field in an optional array" do
136
136
  before { params["optional_nested_array"][0].merge!("non_documented" => true) }
137
137
 
@@ -139,7 +139,7 @@ describe Fdoc::Endpoint do
139
139
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /non_documented/)
140
140
  end
141
141
  end
142
-
142
+
143
143
  context "non document field in a required array" do
144
144
  before { params["required_nested_array"][0].merge!("non_documented" => true) }
145
145
 
@@ -163,7 +163,7 @@ describe Fdoc::Endpoint do
163
163
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /non_documented/)
164
164
  end
165
165
  end
166
-
166
+
167
167
  context "non document field in a deeply nested object" do
168
168
  before { params["required_nested_object"]["optional_second_nested_object"].merge!("non_documented" => true) }
169
169
 
@@ -171,7 +171,7 @@ describe Fdoc::Endpoint do
171
171
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /non_documented/)
172
172
  end
173
173
  end
174
-
174
+
175
175
  context "required field in a deeply nested object is missing" do
176
176
  before { params["required_nested_object"]["optional_second_nested_object"].delete("required_param") }
177
177
 
@@ -179,7 +179,7 @@ describe Fdoc::Endpoint do
179
179
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /required_param/)
180
180
  end
181
181
  end
182
-
182
+
183
183
  context "non document field in a deeply nested object in an array" do
184
184
  before { params["required_nested_array"][0]["optional_second_nested_object"].merge!("non_documented" => true) }
185
185
 
@@ -187,7 +187,7 @@ describe Fdoc::Endpoint do
187
187
  expect { subject }.to raise_exception(JSON::Schema::ValidationError, /non_documented/)
188
188
  end
189
189
  end
190
-
190
+
191
191
  context "required field in a deeply nested object is missing" do
192
192
  before { params["required_nested_array"][0]["optional_second_nested_object"].delete("required_param") }
193
193
 
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'nokogiri'
3
+
4
+ describe Fdoc::BasePresenter do
5
+ class Fdoc::SamplePresenter < Fdoc::BasePresenter
6
+ def to_html
7
+ render_erb('test.html.erb')
8
+ end
9
+ end
10
+
11
+ subject {
12
+ Fdoc::SamplePresenter.new template_directory: 'templates'
13
+ }
14
+
15
+ context "#render_erb" do
16
+ it "renders a default template" do
17
+ File.should_receive(:exists?).with('templates/test.html.erb').and_return(false)
18
+ File.stub(:read).and_return('test content')
19
+ subject.to_html
20
+ end
21
+
22
+ it "renders from local template directory" do
23
+ File.should_receive(:exists?).with('templates/test.html.erb').and_return(true)
24
+ File.should_receive(:read).with('templates/test.html.erb').and_return('test content')
25
+ subject.to_html
26
+ end
27
+ end
28
+ end
@@ -19,6 +19,13 @@ describe Fdoc::EndpointPresenter do
19
19
  end
20
20
  end
21
21
 
22
+ context "#to_markdown" do
23
+ it "should generate markdown" do
24
+ markdown = subject.to_markdown
25
+ markdown.should include "# GET spec&#8203;/fixtures&#8203;/members&#8203;/list"
26
+ end
27
+ end
28
+
22
29
  context "#example_from_schema" do
23
30
  example_schema_yaml = <<-EOS
24
31
  properties:
@@ -90,4 +97,4 @@ describe Fdoc::EndpointPresenter do
90
97
  subject.example_from_schema(example_schema).should == expected_example
91
98
  end
92
99
  end
93
- end
100
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'nokogiri'
3
+
4
+ describe Fdoc::MetaServicePresenter do
5
+ subject {
6
+ Fdoc::MetaServicePresenter.new(Fdoc::MetaService.new('spec/fixtures'))
7
+ }
8
+
9
+ context "#to_html" do
10
+ it "should generate valid HTML" do
11
+ html = subject.to_html
12
+
13
+ expect {
14
+ Nokogiri::HTML(html) { |config| config.strict }
15
+ }.to_not raise_exception
16
+ end
17
+ end
18
+
19
+ context "#to_markdown" do
20
+ it "should generate markdown" do
21
+ markdown = subject.to_markdown
22
+ markdown.should include "* PUT [https:&#8203;/&#8203;/api.sample.com&#8203;/members&#8203;/add](members_api/add-PUT.md)"
23
+ markdown.should include "* POST [https:&#8203;/&#8203;/api.sample.com&#8203;/members&#8203;/draft](members_api/draft-POST.md)"
24
+ end
25
+ end
26
+
27
+ context "#relative_service_path" do
28
+ let(:service) { subject.services.first }
29
+
30
+ it "returns relative path" do
31
+ subject.relative_service_path(service).should == "members_api"
32
+ end
33
+
34
+ it "should join relative path if passed in a filename" do
35
+ subject.relative_service_path(service, 'index.md').should == "members_api/index.md"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'nokogiri'
3
+
4
+ describe Fdoc::SchemaPresenter do
5
+ let(:schema) {
6
+ {
7
+ 'description' => 'Some description text',
8
+ 'example' => 'an example'
9
+ }
10
+ }
11
+ subject {
12
+ Fdoc::SchemaPresenter.new(schema, {})
13
+ }
14
+
15
+ context '#to_html' do
16
+ it 'should generate valid HTML' do
17
+ html = subject.to_html
18
+
19
+ html.should include 'Some description text'
20
+ html.should include 'an example'
21
+ expect {
22
+ Nokogiri::HTML(html) { |config| config.strict }
23
+ }.to_not raise_exception
24
+ end
25
+ end
26
+
27
+ context "#to_markdown" do
28
+ it "should generate markdown" do
29
+ markdown = subject.to_markdown
30
+ markdown.should include 'Some description text'
31
+ markdown.should include 'an example'
32
+ end
33
+ end
34
+ end
@@ -3,7 +3,7 @@ require 'nokogiri'
3
3
 
4
4
  describe Fdoc::ServicePresenter do
5
5
  subject {
6
- Fdoc::ServicePresenter.new(Fdoc::Service.new('spec/fixtures'))
6
+ Fdoc::ServicePresenter.new(Fdoc::Service.new('spec/fixtures/members'))
7
7
  }
8
8
 
9
9
  context "#to_html" do
@@ -15,4 +15,27 @@ describe Fdoc::ServicePresenter do
15
15
  }.to_not raise_exception
16
16
  end
17
17
  end
18
+
19
+ context "#to_markdown" do
20
+ it "should generate markdown" do
21
+ markdown = subject.to_markdown
22
+ markdown.should include "* PUT [https:&#8203;/&#8203;/api.sample.com&#8203;/members&#8203;/add](add-PUT.md)"
23
+ markdown.should include "* POST [https:&#8203;/&#8203;/api.sample.com&#8203;/members&#8203;/draft](draft-POST.md)"
24
+ end
25
+ end
26
+
27
+ context "#relative_meta_service_path" do
28
+ let(:meta_service) { Fdoc::MetaServicePresenter.new(Fdoc::MetaService.new('spec/fixtures')) }
29
+ before do
30
+ subject.service.meta_service = meta_service
31
+ end
32
+
33
+ its(:relative_meta_service_path) { should == "../"}
34
+
35
+ context "pass in filename" do
36
+ it "should join with filename" do
37
+ subject.relative_meta_service_path('index.md').should == "../index.md"
38
+ end
39
+ end
40
+ end
18
41
  end
@@ -4,84 +4,84 @@ requestParameters:
4
4
  toplevel_param:
5
5
  type: string
6
6
  description: A paramater as normal
7
- required: Yes
7
+ required: yes
8
8
  optional_nested_array:
9
9
  type: array
10
- required: No
10
+ required: no
11
11
  items:
12
12
  type: object
13
13
  properties:
14
14
  required_param:
15
- required: Yes
15
+ required: yes
16
16
  description: It's required
17
17
  type: string
18
18
  optional_param:
19
- required: Yes
19
+ required: yes
20
20
  description: It's optional
21
21
  type: string
22
22
  required_nested_array:
23
23
  type: array
24
- required: Yes
24
+ required: yes
25
25
  items:
26
26
  type: object
27
27
  properties:
28
28
  required_param:
29
- required: Yes
29
+ required: yes
30
30
  description: It's required
31
31
  type: string
32
32
  optional_param:
33
- required: No
33
+ required: no
34
34
  description: It's optional
35
35
  type: string
36
36
  optional_second_nested_object:
37
- required: No
37
+ required: no
38
38
  type: object
39
39
  description: It's a bug
40
40
  properties:
41
41
  required_param:
42
- required: Yes
42
+ required: yes
43
43
  description: It's required
44
44
  type: string
45
45
  optional_param:
46
- required: No
46
+ required: no
47
47
  description: It's optional
48
48
  type: string
49
-
49
+
50
50
  optional_nested_object:
51
51
  type: object
52
- required: No
52
+ required: no
53
53
  properties:
54
54
  required_param:
55
- required: Yes
55
+ required: yes
56
56
  description: It's required
57
57
  type: string
58
58
  optional_param:
59
- required: No
59
+ required: no
60
60
  description: It's optional
61
61
  type: string
62
62
  required_nested_object:
63
63
  type: object
64
- required: Yes
64
+ required: yes
65
65
  properties:
66
66
  required_param:
67
- required: Yes
67
+ required: yes
68
68
  description: It's required
69
69
  type: string
70
70
  optional_param:
71
- required: No
71
+ required: no
72
72
  description: It's optional
73
73
  type: string
74
74
  optional_second_nested_object:
75
- required: No
75
+ required: no
76
76
  type: object
77
77
  description: It's a bug
78
78
  properties:
79
79
  required_param:
80
- required: Yes
80
+ required: yes
81
81
  description: It's required
82
82
  type: string
83
83
  optional_param:
84
- required: No
84
+ required: no
85
85
  description: It's optional
86
86
  type: string
87
87
 
@@ -1,6 +1,7 @@
1
1
  require 'fdoc'
2
2
  require 'fdoc/cli'
3
3
  require 'rspec'
4
+ require 'tmpdir'
4
5
 
5
6
  Dir.glob(File.expand_path("../support/*.rb", __FILE__)).each { |f| require f }
6
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -170,8 +170,9 @@ files:
170
170
  - lib/fdoc/endpoint.rb
171
171
  - lib/fdoc/endpoint_scaffold.rb
172
172
  - lib/fdoc/meta_service.rb
173
+ - lib/fdoc/presenters/base_presenter.rb
173
174
  - lib/fdoc/presenters/endpoint_presenter.rb
174
- - lib/fdoc/presenters/html_presenter.rb
175
+ - lib/fdoc/presenters/json_presenter.rb
175
176
  - lib/fdoc/presenters/meta_service_presenter.rb
176
177
  - lib/fdoc/presenters/response_code_presenter.rb
177
178
  - lib/fdoc/presenters/schema_presenter.rb
@@ -179,14 +180,22 @@ files:
179
180
  - lib/fdoc/service.rb
180
181
  - lib/fdoc/spec_watcher.rb
181
182
  - lib/fdoc/templates/endpoint.html.erb
183
+ - lib/fdoc/templates/endpoint.md.erb
182
184
  - lib/fdoc/templates/meta_service.html.erb
185
+ - lib/fdoc/templates/meta_service.md.erb
183
186
  - lib/fdoc/templates/service.html.erb
187
+ - lib/fdoc/templates/service.md.erb
188
+ - lib/fdoc/templates/shared/endpoint_name.html.erb
189
+ - lib/fdoc/templates/shared/endpoint_name.md.erb
184
190
  - lib/fdoc/templates/styles.css
185
191
  - lib/fdoc.rb
186
192
  - spec/fdoc/cli_spec.rb
187
193
  - spec/fdoc/endpoint_scaffold_spec.rb
188
194
  - spec/fdoc/endpoint_spec.rb
195
+ - spec/fdoc/presenters/base_presenter_spec.rb
189
196
  - spec/fdoc/presenters/endpoint_presenter_spec.rb
197
+ - spec/fdoc/presenters/meta_service_presenter_spec.rb
198
+ - spec/fdoc/presenters/schema_presenter_spec.rb
190
199
  - spec/fdoc/presenters/service_presenter_spec.rb
191
200
  - spec/fdoc/service_spec.rb
192
201
  - spec/fdoc/spec_watcher_spec.rb
@@ -233,7 +242,10 @@ test_files:
233
242
  - spec/fdoc/cli_spec.rb
234
243
  - spec/fdoc/endpoint_scaffold_spec.rb
235
244
  - spec/fdoc/endpoint_spec.rb
245
+ - spec/fdoc/presenters/base_presenter_spec.rb
236
246
  - spec/fdoc/presenters/endpoint_presenter_spec.rb
247
+ - spec/fdoc/presenters/meta_service_presenter_spec.rb
248
+ - spec/fdoc/presenters/schema_presenter_spec.rb
237
249
  - spec/fdoc/presenters/service_presenter_spec.rb
238
250
  - spec/fdoc/service_spec.rb
239
251
  - spec/fdoc/spec_watcher_spec.rb