Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display params in a nested format also in the API doc HTML. #691

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/views/apipie/apipies/_method_detail.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<% unless method[:params].blank? %>
<%= heading(t('apipie.params'), h_level) %>
<%= render(:partial => "params_simple", :locals => {:params => method[:params]}) %>
<table class='table'>
<thead>
<tr>
Expand All @@ -44,6 +45,7 @@
<%= heading("#{t('apipie.description')}:", h_level + 2) %>
<p><%= item[:description] %></p>
<% end %>
<%= render(:partial => "params_simple", :locals => {:params => item[:returns_object]}) %>
<table class='table'>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion app/views/apipie/apipies/_params.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= render(:partial => "params", :locals => {:level => level, :params => param[:params]}) unless param[:params].blank? %>
<% next %>
<% end %>
<tr style='background-color:rgb(<%= "#{col},#{col},#{col}" %>);'>
<tr id="<%= param[:full_name] %>" style='background-color:rgb(<%= "#{col},#{col},#{col}" %>);'>
<td>
<strong><%= param[:full_name] %></strong>
<% if param[:deprecated].present? %>
Expand Down
49 changes: 49 additions & 0 deletions app/views/apipie/apipies/_params_simple.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<ul>
<% params.each do |param| %>
<% if !param[:show] %>
<%= render(:partial => "params_simple", :locals => {:params => param[:params]}) unless param[:params].blank? %>
<% next %>
<% end %>
<li>
<span>
<b>
<a href="#<%= param[:full_name] %>" data-toggle="tooltip" data-placement="top" title="<%= param[:description] ? param[:description] : param[:name] %>">
<%= param[:name] %>
</a>
</b>
</span>
<%- if param[:required] %>
<span style="color: red">* </span>
<%- end %>
<%- if param[:validator].present? %>
<span>: </span>
<span style="margin-left: 10px;">
<% if param[:validator].include? "one of" %>
<%= param[:validator].html_safe %>
<%- else %>
<%- if param[:is_array] || param[:expected_type] == "array" %>
<span> [ </span>
<%- end %>
<%- if param[:expected_type] == "hash" && !param[:is_array] %>
<span> { </span>
<%- elsif param[:params].blank? %>
<%= param[:expected_type] %>
<%- if (param[:is_array] || param[:expected_type] == "array") %>
<span> ] </span>
<%- end %>
<%- end %>
<% end %>
</span>
<%- end %>
</li>
<% if param[:params].present? %>
<%= render(:partial => "params_simple", :locals => {:params => param[:params]}) unless param[:params].blank? %>
<%- if param[:expected_type] == "hash" && !param[:is_array] %>
<span> } </span>
<%- end %>
<%- if param[:is_array] || param[:expected_type] == "array" %>
<span> ] </span>
<%- end %>
<% end %>
<% end %>
</ul>
1 change: 1 addition & 0 deletions lib/apipie/param_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def to_json(lang = nil)
required: required,
allow_nil: allow_nil,
allow_blank: allow_blank,
is_array: is_array,
validator: validator.to_s,
expected_type: validator.expected_type,
metadata: metadata,
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def reload_controllers
:required => false,
:allow_nil => true,
:allow_blank => false,
:is_array => nil,
:metadata => nil,
:show => true,
:deprecated => false,
Expand Down