Skip to content

Commit 7733656

Browse files
committed
hash parameters changes (parent parameter is now included in json), validators respond to expected_type - needed for cli client
1 parent 3e0e2b4 commit 7733656

16 files changed

+249
-164
lines changed

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source "http://rubygems.org"
22

3-
gem "rails", "3.0.11"
3+
gem "rails", ">= 3.0.11"
44
gem "sqlite3"
55

66
group :development, :test do
@@ -9,4 +9,5 @@ group :development, :test do
99
gem "redcarpet"
1010
gem "RedCloth"
1111
gem "rake"
12+
gem "weary", ">= 1.0.1"
1213
end

Gemfile.lock

+83-64
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,116 @@ GEM
22
remote: http://rubygems.org/
33
specs:
44
RedCloth (4.2.9)
5-
abstract (1.0.0)
6-
actionmailer (3.0.11)
7-
actionpack (= 3.0.11)
8-
mail (~> 2.2.19)
9-
actionpack (3.0.11)
10-
activemodel (= 3.0.11)
11-
activesupport (= 3.0.11)
12-
builder (~> 2.1.2)
13-
erubis (~> 2.6.6)
14-
i18n (~> 0.5.0)
15-
rack (~> 1.2.1)
16-
rack-mount (~> 0.6.14)
17-
rack-test (~> 0.5.7)
18-
tzinfo (~> 0.3.23)
19-
activemodel (3.0.11)
20-
activesupport (= 3.0.11)
21-
builder (~> 2.1.2)
22-
i18n (~> 0.5.0)
23-
activerecord (3.0.11)
24-
activemodel (= 3.0.11)
25-
activesupport (= 3.0.11)
26-
arel (~> 2.0.10)
27-
tzinfo (~> 0.3.23)
28-
activeresource (3.0.11)
29-
activemodel (= 3.0.11)
30-
activesupport (= 3.0.11)
31-
activesupport (3.0.11)
32-
arel (2.0.10)
33-
builder (2.1.2)
5+
actionmailer (3.2.3)
6+
actionpack (= 3.2.3)
7+
mail (~> 2.4.4)
8+
actionpack (3.2.3)
9+
activemodel (= 3.2.3)
10+
activesupport (= 3.2.3)
11+
builder (~> 3.0.0)
12+
erubis (~> 2.7.0)
13+
journey (~> 1.0.1)
14+
rack (~> 1.4.0)
15+
rack-cache (~> 1.2)
16+
rack-test (~> 0.6.1)
17+
sprockets (~> 2.1.2)
18+
activemodel (3.2.3)
19+
activesupport (= 3.2.3)
20+
builder (~> 3.0.0)
21+
activerecord (3.2.3)
22+
activemodel (= 3.2.3)
23+
activesupport (= 3.2.3)
24+
arel (~> 3.0.2)
25+
tzinfo (~> 0.3.29)
26+
activeresource (3.2.3)
27+
activemodel (= 3.2.3)
28+
activesupport (= 3.2.3)
29+
activesupport (3.2.3)
30+
i18n (~> 0.6)
31+
multi_json (~> 1.0)
32+
addressable (2.2.8)
33+
arel (3.0.2)
34+
builder (3.0.0)
3435
diff-lcs (1.1.3)
35-
erubis (2.6.6)
36-
abstract (>= 1.0.0)
37-
i18n (0.5.0)
38-
json (1.6.5)
39-
mail (2.2.19)
40-
activesupport (>= 2.3.6)
36+
erubis (2.7.0)
37+
hike (1.2.1)
38+
i18n (0.6.0)
39+
journey (1.0.3)
40+
json (1.7.3)
41+
mail (2.4.4)
4142
i18n (>= 0.4.0)
4243
mime-types (~> 1.16)
4344
treetop (~> 1.4.8)
44-
mime-types (1.17.2)
45+
mime-types (1.18)
46+
multi_json (1.2.0)
4547
polyglot (0.3.3)
46-
rack (1.2.5)
47-
rack-mount (0.6.14)
48-
rack (>= 1.0.0)
49-
rack-test (0.5.7)
48+
promise (0.3.0)
49+
rack (1.4.1)
50+
rack-cache (1.2)
51+
rack (>= 0.4)
52+
rack-ssl (1.3.2)
53+
rack
54+
rack-test (0.6.1)
5055
rack (>= 1.0)
51-
rails (3.0.11)
52-
actionmailer (= 3.0.11)
53-
actionpack (= 3.0.11)
54-
activerecord (= 3.0.11)
55-
activeresource (= 3.0.11)
56-
activesupport (= 3.0.11)
56+
rails (3.2.3)
57+
actionmailer (= 3.2.3)
58+
actionpack (= 3.2.3)
59+
activerecord (= 3.2.3)
60+
activeresource (= 3.2.3)
61+
activesupport (= 3.2.3)
5762
bundler (~> 1.0)
58-
railties (= 3.0.11)
59-
railties (3.0.11)
60-
actionpack (= 3.0.11)
61-
activesupport (= 3.0.11)
63+
railties (= 3.2.3)
64+
railties (3.2.3)
65+
actionpack (= 3.2.3)
66+
activesupport (= 3.2.3)
67+
rack-ssl (~> 1.3.2)
6268
rake (>= 0.8.7)
6369
rdoc (~> 3.4)
64-
thor (~> 0.14.4)
70+
thor (~> 0.14.6)
6571
rake (0.9.2.2)
6672
rdoc (3.12)
6773
json (~> 1.4)
6874
redcarpet (2.1.1)
69-
rspec (2.8.0)
70-
rspec-core (~> 2.8.0)
71-
rspec-expectations (~> 2.8.0)
72-
rspec-mocks (~> 2.8.0)
73-
rspec-core (2.8.0)
74-
rspec-expectations (2.8.0)
75-
diff-lcs (~> 1.1.2)
76-
rspec-mocks (2.8.0)
77-
rspec-rails (2.8.1)
75+
rspec (2.10.0)
76+
rspec-core (~> 2.10.0)
77+
rspec-expectations (~> 2.10.0)
78+
rspec-mocks (~> 2.10.0)
79+
rspec-core (2.10.0)
80+
rspec-expectations (2.10.0)
81+
diff-lcs (~> 1.1.3)
82+
rspec-mocks (2.10.1)
83+
rspec-rails (2.10.1)
7884
actionpack (>= 3.0)
7985
activesupport (>= 3.0)
8086
railties (>= 3.0)
81-
rspec (~> 2.8.0)
82-
sqlite3 (1.3.5)
87+
rspec (~> 2.10.0)
88+
simple_oauth (0.1.8)
89+
sprockets (2.1.3)
90+
hike (~> 1.2)
91+
rack (~> 1.0)
92+
tilt (~> 1.1, != 1.3.0)
93+
sqlite3 (1.3.6)
8394
thor (0.14.6)
95+
tilt (1.3.3)
8496
treetop (1.4.10)
8597
polyglot
8698
polyglot (>= 0.3.1)
87-
tzinfo (0.3.31)
99+
tzinfo (0.3.33)
100+
weary (1.0.1)
101+
addressable (~> 2.2.7)
102+
multi_json (~> 1.2.0)
103+
promise (~> 0.3.0)
104+
rack (~> 1.4.0)
105+
simple_oauth (~> 0.1.5)
88106

89107
PLATFORMS
90108
ruby
91109

92110
DEPENDENCIES
93111
RedCloth
94-
rails (= 3.0.11)
112+
rails (>= 3.0.11)
95113
rake
96114
redcarpet
97115
rspec-rails
98116
sqlite3
117+
weary (>= 1.0.1)
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Restapi
2+
module RestapisHelper
3+
4+
def print_nested_params(param, level=0)
5+
content = ''
6+
7+
unless param[:params].blank?
8+
param[:params].each do |val|
9+
col = 255 - level*5
10+
content << "<tr style='background-color:rgb(#{col},#{col},#{col});'><td>"
11+
content << ("<strong>#{val[:full_name]}</strong><br>")
12+
content << "<small>"
13+
content << (val[:required] ? 'required' : 'optional')
14+
content << (val[:allow_nil] ? ', nil allowed' : '')
15+
content << "</small>"
16+
content << "</td><td>"
17+
content << val[:description].html_safe
18+
content << "<br>"
19+
unless val[:validator].blank?
20+
content << "Value: #{val[:validator]}"
21+
end
22+
content << "</td></tr>"
23+
24+
content << print_nested_params(val, level+1) unless val[:params].blank?
25+
end
26+
end
27+
content.html_safe
28+
end
29+
30+
end
31+
end

app/views/restapi/restapis/index.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<li class='active'><a href='<%= @doc[:doc_url] %>'><%= @doc[:name] %></a></li>
33
</ul>
44

5-
<div class=''><%= @doc[:info].html_safe %></div>
5+
<div><%= @doc[:info].html_safe %></div>
6+
7+
<h1 class='page-header'>Resources</h1>
68

79
<% @doc[:resources].each do |key, api| %>
810
<h2>

app/views/restapi/restapis/method.html.erb

+1-17
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,7 @@
4848
</tr>
4949
</thead>
5050
<tbody>
51-
<% @method[:params].each do |val| %>
52-
<tr>
53-
<td>
54-
<strong><%= val[:name] %></strong><br>
55-
<small>
56-
<%= val[:required] ? 'required' : 'optional' %>
57-
<%= val[:allow_nil] ? ', nil allowed' : '' %>
58-
</small>
59-
</td>
60-
<td>
61-
<%= raw val[:description] %><br>
62-
<% unless val[:validator].blank? %>
63-
Value: <%= val[:validator] %>
64-
<% end %>
65-
</td>
66-
</tr>
67-
<% end %>
51+
<%= print_nested_params(@method) %>
6852
</tbody>
6953
</table>
7054
<% end %>

app/views/restapi/restapis/resource.html.erb

+5-22
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@
2424
</div>
2525
<div>
2626
<% m[:apis].each do |api| %>
27-
<h3>
27+
<h2>
2828
<a href='#description-<%= m[:name] %>'
2929
class='accordion-toggle'
3030
data-toggle='collapse'
3131
data-parent='#accordion'>
3232
<%= api[:http_method] %> <%= api[:api_url] %>
3333
</a><br>
3434
<small><%= raw api[:short_description] %></small>
35-
</h3>
35+
</h2>
3636
<% end %>
3737
</div>
3838

3939
<div id='description-<%= m[:name] %>' class='collapse accordion-body'>
4040

4141
<%= raw m[:full_description] %>
4242
<% unless m[:errors].blank? %>
43-
<h2>Errors</h2>
43+
<h3>Errors</h3>
4444
<% m[:errors].each do |err| %>
4545
<%= err.code %>
4646
<%= err.description %>
@@ -49,7 +49,7 @@
4949
<% end %>
5050

5151
<% unless m[:params].blank? %>
52-
<h2>Params</h2>
52+
<h3>Params</h3>
5353
<table class='table'>
5454
<thead>
5555
<tr>
@@ -58,24 +58,7 @@
5858
</tr>
5959
</thead>
6060
<tbody>
61-
<% m[:params].each do |val| %>
62-
<tr>
63-
<td>
64-
<strong><%= val[:name] %></strong><br>
65-
<small>
66-
<%= val[:required] ? 'required' : 'optional' %>
67-
<%= val[:allow_nil] ? ', nil allowed' : '' %>
68-
</small>
69-
</td>
70-
<td>
71-
<%= raw val[:description] %><br>
72-
73-
<% unless val[:validator].blank? %>
74-
Value: <%= val[:validator] %>
75-
<% end %>
76-
</td>
77-
</tr>
78-
<% end %>
61+
<%= print_nested_params(m) %>
7962
</tbody>
8063
</table>
8164
<% end %>

lib/restapi.rb

-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
require 'active_support/dependencies'
2-
3-
# add path to restapi controller to ActiveSupport paths
4-
%w{ controllers views }.each do |dir|
5-
path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'app', dir))
6-
$LOAD_PATH << path
7-
ActiveSupport::Dependencies.autoload_paths << path
8-
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
9-
end
10-
111
require "restapi/routing"
122
require "restapi/markup"
133
require "restapi/restapi_module"

lib/restapi/dsl_definition.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def param(param_name, *args, &block) #:doc:
7777
end
7878

7979
# create method api and redefine newly added method
80-
def method_added(method_name) #:doc:s
80+
def method_added(method_name) #:doc:
8181

8282
super
8383

lib/restapi/param_description.rb

+14-3
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,25 @@ def parents_and_self
5959

6060
def to_json
6161
if validator.is_a? Restapi::Validator::HashValidator
62-
validator.hash_params_ordered.map(&:to_json)
62+
{
63+
:name => name.to_s,
64+
:full_name => full_name,
65+
:description => desc,
66+
:required => required,
67+
:allow_nil => allow_nil,
68+
:validator => validator.to_s,
69+
:expected_type => validator.expected_type,
70+
:params => validator.hash_params_ordered.map(&:to_json)
71+
}
6372
else
6473
{
65-
:name => full_name,
74+
:name => name.to_s,
75+
:full_name => full_name,
6676
:description => desc,
6777
:required => required,
6878
:allow_nil => allow_nil,
69-
:validator => validator.to_s
79+
:validator => validator.to_s,
80+
:expected_type => validator.expected_type
7081
}
7182
end
7283
end

0 commit comments

Comments
 (0)