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

Fixes #115

Merged
merged 6 commits into from
Jan 31, 2020
Merged

Fixes #115

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: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rvm:
addons:
chrome: stable
before_script:
- sh -e /etc/init.d/xvfb start
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/apitome/docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,19 @@ def rendered_markdown(string)
end

def formatted_body(body, type)
return body if body == " "
return body if body == "[binary data]" # see https://github.com/zipmark/rspec_api_documentation/blob/560c3bdc7bd5581e7c223334390221ecfc910be8/lib/rspec_api_documentation/client_base.rb#L88-L96
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor and 🐞 fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "[binary data"] change was related in our app to changing from - rack (2.0.8) to rack (2.1.1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if type =~ /json/ && body.present?
JSON.pretty_generate(JSON.parse(body))
else
body
end
rescue JSON::ParserError
return body if body == " "
raise JSON::ParserError
rescue => e
if Apitome.configuration.formatted_body_error_handler
Apitome.configuration.formatted_body_error_handler.call(e, body, type)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else
raise
end
end

def param_headers(params)
Expand Down
20 changes: 20 additions & 0 deletions app/views/apitome/docs/_example.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,42 @@
<div id="<%= "request-#{index}" %>">
<h3><%= t(:request, scope: :apitome) %></h3>
<div class="request">
<% begin %>
<%= render partial: 'apitome/docs/route', locals: {request: request, index: index} %>
<%= render partial: 'apitome/docs/headers', locals: {request: request, index: index, headers: request['request_headers']} %>
<%= render partial: 'apitome/docs/query', locals: {request: request, index: index} unless request['request_query_parameters'].empty? %>
<%= render partial: 'apitome/docs/body', locals: {request: request, index: index, body: request['request_body'], type: request['request_content_type']} if request['request_body'] %>
<%= render partial: 'apitome/docs/curl', locals: {request: request, index: index} if request['curl'] %>
<%
rescue => e
if Apitome.configuration.example_error_handler
Apitome.configuration.example_error_handler.call(e, "request", request)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else
raise
end
end
%>
</div>

<h3><%= t(:response, scope: :apitome) %></h3>
<div class="response">
<% begin %>
<%- if Apitome.configuration.simulated_response %>
<%= link_to('Simulated Response', simulated_path(example[:link])) if example[:link].present? %>
<%- end %>
<%= render partial: 'apitome/docs/response_fields', locals: {params: example['response_fields']} if example['response_fields'].size > 0 %>
<%= render partial: 'apitome/docs/status', locals: {request: request, index: index} %>
<%= render partial: 'apitome/docs/headers', locals: {request: request, index: index, headers: request['response_headers']} %>
<%= render partial: 'apitome/docs/body', locals: {request: request, index: index, body: request['response_body'], type: request['response_content_type']} if request['response_body'] %>
<%
rescue => e
if Apitome.configuration.example_error_handler
Apitome.configuration.example_error_handler.call(e, "response", request)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else
raise
end
end
%>
</div>
</div>
<% end %>
4 changes: 4 additions & 0 deletions lib/apitome/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Configuration
:http_basic_authentication,
:precompile_assets,
:simulated_response,
:formatted_body_error_handler,
:example_error_handler,
])

@@mount_at = "/api/docs"
Expand All @@ -39,6 +41,8 @@ class Configuration
@@http_basic_authentication = nil
@@precompile_assets = true
@@simulated_response = true
@@formatted_body_error_handler = nil
@@example_error_handler = nil

def self.root=(path)
@@root = Pathname.new(path.to_s) if path.present?
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link apitome/application.css
//= link apitome/application.js
//= link apitome/highlight_themes/default.css
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐞 fix