Skip to content

Commit 9f04200

Browse files
authored
Merge pull request #387 from obromios/documentation_obromios
Documentation obromios
2 parents 88f2837 + 93e7684 commit 9f04200

File tree

6 files changed

+132
-36
lines changed

6 files changed

+132
-36
lines changed

Gemfile.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ GEM
3434
xpath (~> 2.0)
3535
childprocess (0.5.9)
3636
ffi (~> 1.0, >= 1.0.11)
37-
coderay (1.1.0)
37+
coderay (1.1.2)
3838
contracts (0.13.0)
3939
crack (0.4.3)
4040
safe_yaml (~> 1.0.0)
@@ -60,13 +60,13 @@ GEM
6060
hashdiff (0.2.3)
6161
httpclient (2.7.1)
6262
i18n (0.7.0)
63-
inch (0.7.0)
63+
inch (0.8.0)
6464
pry
6565
sparkr (>= 0.2.0)
6666
term-ansicolor
67-
yard (~> 0.8.7.5)
67+
yard (~> 0.9.12)
6868
json (1.8.6)
69-
method_source (0.8.2)
69+
method_source (0.9.0)
7070
mime-types (3.0)
7171
mime-types-data (~> 3.2015)
7272
mime-types-data (3.2015.1120)
@@ -76,12 +76,11 @@ GEM
7676
multi_test (0.1.2)
7777
multipart-post (2.0.0)
7878
mustache (1.0.3)
79-
nokogiri (1.8.1)
79+
nokogiri (1.8.4)
8080
mini_portile2 (~> 2.3.0)
81-
pry (0.10.3)
81+
pry (0.11.3)
8282
coderay (~> 1.1.0)
83-
method_source (~> 0.8.1)
84-
slop (~> 3.4)
83+
method_source (~> 0.9.0)
8584
rack (1.6.4)
8685
rack-oauth2 (1.2.2)
8786
activesupport (>= 2.3)
@@ -115,9 +114,8 @@ GEM
115114
rack (~> 1.5)
116115
rack-protection (~> 1.4)
117116
tilt (>= 1.3, < 3)
118-
slop (3.6.0)
119117
sparkr (0.4.1)
120-
term-ansicolor (1.3.2)
118+
term-ansicolor (1.6.0)
121119
tins (~> 1.0)
122120
thin (1.6.4)
123121
daemons (~> 1.0, >= 1.0.9)
@@ -126,7 +124,7 @@ GEM
126124
thor (0.19.1)
127125
thread_safe (0.3.5)
128126
tilt (2.0.2)
129-
tins (1.8.2)
127+
tins (1.16.3)
130128
tzinfo (1.2.2)
131129
thread_safe (~> 0.1)
132130
webmock (1.22.6)
@@ -135,7 +133,7 @@ GEM
135133
hashdiff
136134
xpath (2.0.0)
137135
nokogiri (~> 1.3)
138-
yard (0.8.7.6)
136+
yard (0.9.15)
139137

140138
PLATFORMS
141139
ruby
@@ -147,6 +145,7 @@ DEPENDENCIES
147145
fakefs (~> 0.4)
148146
faraday (~> 0.9, >= 0.9.0)
149147
inch
148+
nokogiri (~> 1.8, >= 1.8.2)
150149
rack-oauth2 (~> 1.2.2, >= 1.0.7)
151150
rack-test (~> 0.6.2)
152151
rake (~> 10.1)
@@ -155,6 +154,7 @@ DEPENDENCIES
155154
sinatra (~> 1.4, >= 1.4.4)
156155
thin (~> 1.6, >= 1.6.3)
157156
webmock (~> 1.7)
157+
yard (>= 0.9.11)
158158

159159
BUNDLED WITH
160-
1.16.1
160+
1.16.3

README.md

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Consider adding a viewer to enhance the generated documentation. By itself rspec
6060

6161
gem 'raddocs'
6262

63+
or
64+
65+
gem 'apitome'
66+
6367
#### spec/spec_helper.rb
6468

6569
```ruby
@@ -68,9 +72,106 @@ RspecApiDocumentation.configure do |config|
6872
end
6973
```
7074

75+
####
76+
For both raddocs and apitome, start rails server. Then
77+
78+
open http://localhost:3000/docs for raddocs
79+
80+
or
81+
82+
http://localhost:3000/api/docs for apitome
83+
7184
## Sample App
7285

73-
See the `example` folder for a sample Rails app that has been documented.
86+
See the `example` folder for a sample Rails app that has been documented. The sample app demonstrates the :open_api format.
87+
88+
## Example of spec file
89+
90+
```ruby
91+
# spec/acceptance/orders_spec.rb
92+
require 'rails_helper'
93+
require 'rspec_api_documentation/dsl'
94+
resource 'Orders' do
95+
explanation "Orders resource"
96+
97+
header "Content-Type", "application/json"
98+
99+
get '/orders' do
100+
# This is manual way to describe complex parameters
101+
parameter :one_level_array, type: :array, items: {type: :string, enum: ['string1', 'string2']}, default: ['string1']
102+
parameter :two_level_array, type: :array, items: {type: :array, items: {type: :string}}
103+
104+
let(:one_level_array) { ['string1', 'string2'] }
105+
let(:two_level_array) { [['123', '234'], ['111']] }
106+
107+
# This is automatic way
108+
# It's possible because we extract parameters definitions from the values
109+
parameter :one_level_arr, with_example: true
110+
parameter :two_level_arr, with_example: true
111+
112+
let(:one_level_arr) { ['value1', 'value2'] }
113+
let(:two_level_arr) { [[5.1, 3.0], [1.0, 4.5]] }
114+
115+
context '200' do
116+
example_request 'Getting a list of orders' do
117+
expect(status).to eq(200)
118+
end
119+
end
120+
end
121+
122+
put '/orders/:id' do
123+
124+
with_options scope: :data, with_example: true do
125+
parameter :name, 'The order name', required: true
126+
parameter :amount
127+
parameter :description, 'The order description'
128+
end
129+
130+
context "200" do
131+
let(:id) { 1 }
132+
133+
example 'Update an order' do
134+
request = {
135+
data: {
136+
name: 'order',
137+
amount: 1,
138+
description: 'fast order'
139+
}
140+
}
141+
142+
# It's also possible to extract types of parameters when you pass data through `do_request` method.
143+
do_request(request)
144+
145+
expected_response = {
146+
data: {
147+
name: 'order',
148+
amount: 1,
149+
description: 'fast order'
150+
}
151+
}
152+
expect(status).to eq(200)
153+
expect(response_body).to eq(expected_response)
154+
end
155+
end
156+
157+
context "400" do
158+
let(:id) { "a" }
159+
160+
example_request 'Invalid request' do
161+
expect(status).to eq(400)
162+
end
163+
end
164+
165+
context "404" do
166+
let(:id) { 0 }
167+
168+
example_request 'Order is not found' do
169+
expect(status).to eq(404)
170+
end
171+
end
172+
end
173+
end
174+
```
74175

75176

76177
## Configuration options
@@ -306,9 +407,7 @@ paths:
306407
description: This description came from configuration file
307408
hide: true
308409
```
309-
310-
#### Example of spec file
311-
410+
#### Example of spec file with :open_api format
312411
```ruby
313412
resource 'Orders' do
314413
explanation "Orders resource"

example/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ gem 'rack-cors', :require => 'rack/cors'
66
gem 'rails', '4.2.5.1'
77
gem 'sqlite3'
88
gem 'spring', group: :development
9-
gem 'raddocs', :github => "smartlogic/raddocs"
9+
gem 'raddocs', '0.4.0'
1010

1111
group :test, :development do
1212
gem 'byebug'

example/Gemfile.lock

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
GIT
2-
remote: git://github.com/smartlogic/raddocs.git
3-
revision: 9cf49c1ef3b3d7dc3bf8e19ef75021040df04652
4-
specs:
5-
raddocs (0.4.0)
6-
haml (~> 4.0, >= 4.0.4)
7-
json (~> 1.8, >= 1.8.1)
8-
sinatra (~> 1.3, >= 1.3.0)
9-
101
PATH
112
remote: ..
123
specs:
@@ -62,7 +53,7 @@ GEM
6253
erubis (2.7.0)
6354
globalid (0.3.6)
6455
activesupport (>= 4.1.0)
65-
haml (4.0.5)
56+
haml (4.0.7)
6657
tilt
6758
i18n (0.7.0)
6859
json (1.8.3)
@@ -78,10 +69,14 @@ GEM
7869
mini_portile2 (~> 2.0.0.rc2)
7970
rack (1.6.4)
8071
rack-cors (0.4.1)
81-
rack-protection (1.5.3)
72+
rack-protection (1.5.5)
8273
rack
8374
rack-test (0.6.3)
8475
rack (>= 1.0)
76+
raddocs (0.4.0)
77+
haml (~> 4.0, >= 4.0.4)
78+
json (~> 1.8, >= 1.8.1)
79+
sinatra (~> 1.3, >= 1.3.0)
8580
rails (4.2.5.1)
8681
actionmailer (= 4.2.5.1)
8782
actionpack (= 4.2.5.1)
@@ -127,10 +122,10 @@ GEM
127122
rspec-mocks (~> 3.0.0)
128123
rspec-support (~> 3.0.0)
129124
rspec-support (3.0.4)
130-
sinatra (1.4.5)
131-
rack (~> 1.4)
125+
sinatra (1.4.8)
126+
rack (~> 1.5)
132127
rack-protection (~> 1.4)
133-
tilt (~> 1.3, >= 1.3.4)
128+
tilt (>= 1.3, < 3)
134129
spring (1.1.3)
135130
sprockets (3.5.2)
136131
concurrent-ruby (~> 1.0)
@@ -142,7 +137,7 @@ GEM
142137
sqlite3 (1.3.9)
143138
thor (0.19.1)
144139
thread_safe (0.3.5)
145-
tilt (1.4.1)
140+
tilt (2.0.8)
146141
tzinfo (1.2.2)
147142
thread_safe (~> 0.1)
148143

@@ -153,7 +148,7 @@ DEPENDENCIES
153148
awesome_print
154149
byebug
155150
rack-cors
156-
raddocs!
151+
raddocs (= 0.4.0)
157152
rails (= 4.2.5.1)
158153
rspec-rails
159154
rspec_api_documentation!
@@ -164,4 +159,4 @@ RUBY VERSION
164159
ruby 2.3.3p222
165160

166161
BUNDLED WITH
167-
1.16.2
162+
1.16.3

example/spec/acceptance_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rspec_api_documentation/dsl'
44

55
RspecApiDocumentation.configure do |config|
6-
config.format = [:open_api]
6+
config.format = [:open_api, :html]
77
config.curl_host = 'http://localhost:3000'
88
config.api_name = "Example App API"
99
config.api_explanation = "API Example Description"

rspec_api_documentation.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
3030
s.add_development_dependency "rspec-its", "~> 1.0"
3131
s.add_development_dependency "faraday", "~> 0.9", ">= 0.9.0"
3232
s.add_development_dependency "thin", "~> 1.6", ">= 1.6.3"
33+
s.add_development_dependency "nokogiri", "~> 1.8", ">= 1.8.2"
34+
s.add_development_dependency "yard", ">= 0.9.11"
3335

3436
s.files = Dir.glob("lib/**/*") + Dir.glob("templates/**/*")
3537
s.require_path = "lib"

0 commit comments

Comments
 (0)