-
Notifications
You must be signed in to change notification settings - Fork 459
Request data as json #598
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
Request data as json #598
Changes from all commits
a310716
a996c54
9b5e735
aed8772
2fc0626
7c799b1
1d91ac1
530b131
352157e
4fc3dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <div class="panel panel-<%= example[:code].to_i >= 400 ? 'danger' : 'success' %>"> | ||
| <div class="panel-heading"> | ||
| <a role href="#example-<%= index %>" data-toggle="collapse"> | ||
| <%= example[:path] %> | ||
| <%- if !example[:request_data].blank? %> | ||
| with | ||
| <%= example[:request_data] %> | ||
| <% end %> | ||
| <span class="caret right"></span> | ||
| </a> | ||
| </div> | ||
| <div class="panel-body container"> | ||
| <div class="row"> | ||
| <div class="col-sm-12"> | ||
| <h4>Path:</h4> | ||
| <pre class="prettyprint"><%= example[:path] %> | ||
| </pre> | ||
| <%- if !example[:request_data].blank? %> | ||
| <h4>Request Data:</h4> | ||
| <pre class="prettyprint"><%= example[:request_data] %></pre> | ||
| <h4>Request Data Json:</h4> | ||
| <pre class="prettyprint"><%= example[:request_data_json] %></pre> | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col-sm-12"> | ||
| <h4>Response Data:</h4> | ||
| <pre class="prettyprint"><%= example[:response_data] %></pre> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <div class='panel panel-default'> | ||
| <div class='panel-heading'> | ||
| <a role='button' | ||
| href='#example-<%= "#{index}#{example.lines.first.underscore}" %>' | ||
| data-toggle="collapse" | ||
| aria-controls='example-<%= "#{index}#{example.lines.first.underscore}" %>'> | ||
| <%= example.lines.first %> | ||
| <span class='caret right'></span> | ||
| </a> | ||
| </div> | ||
| <div id='example-<%= "#{index}#{example.lines.first.underscore}" %>' | ||
| aria-controls='example-<%= "#{index}#{example.lines.first.underscore}" %>' | ||
| aria-expanded='false' | ||
| class='panel-collapse collapse'> | ||
| <div class='panel-body'> | ||
| <h4>Response Data:</h4> | ||
| <pre class="prettyprint pre-scrollable" style='max-height: 600px'><%= example %></pre> | ||
| </div> | ||
| </div> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,11 @@ def analyse_env(env) | |
| @verb = env["REQUEST_METHOD"].to_sym | ||
| @path = env["PATH_INFO"].sub(/^\/*/,"/") | ||
| @query = env["QUERY_STRING"] unless env["QUERY_STRING"].blank? | ||
| input = env['rack.input'].read | ||
| @params = Rack::Utils.parse_nested_query(@query) | ||
| @params.merge!(env["action_dispatch.request.request_parameters"] || {}) | ||
| if data = parse_data(env["rack.input"].read) | ||
| .merge(env['action_dispatch.request.request_parameters'] || {}) | ||
| .merge(Rack::Utils.parse_nested_query(input) || {}) | ||
| if data = parse_data(input) | ||
| @request_data = data | ||
| env["rack.input"].rewind | ||
| elsif form_hash = env["rack.request.form_hash"] | ||
|
|
@@ -109,7 +111,8 @@ def record | |
| :path => @path, | ||
| :params => @params, | ||
| :query => @query, | ||
| :request_data => @request_data, | ||
| :request_data => request_data, | ||
| :request_data_json => @params, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this differ from |
||
| :response_data => @response_data, | ||
| :code => @code} | ||
| else | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| require 'set' | ||
| module Apipie | ||
|
|
||
| class MethodDescription | ||
|
|
||
| class Api | ||
|
|
||
| attr_accessor :short_description, :path, :http_method, :from_routes, :options | ||
|
|
@@ -14,7 +12,6 @@ def initialize(method, path, desc, options) | |
| @from_routes = options[:from_routes] | ||
| @options = options | ||
| end | ||
|
|
||
| end | ||
|
|
||
| attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata, :headers, :show | ||
|
|
@@ -194,7 +191,12 @@ def load_recorded_examples | |
| find_all { |ex| ex["show_in_doc"].to_i > 0 }. | ||
| find_all { |ex| ex["versions"].nil? || ex["versions"].include?(self.version) }. | ||
| sort_by { |ex| ex["show_in_doc"] }. | ||
| map { |ex| format_example(ex.symbolize_keys) } | ||
| map do |ex| | ||
| %w(request_data response_data request_data_json).each do |key| | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beware of indentation |
||
| ex[key] = format_example_data(ex[key]) if ex[key] | ||
| end | ||
| ex | ||
| end.map(&:symbolize_keys) | ||
| end | ||
|
|
||
| def format_example_data(data) | ||
|
|
@@ -206,17 +208,6 @@ def format_example_data(data) | |
| end | ||
| end | ||
|
|
||
| def format_example(ex) | ||
| example = "" | ||
| example << "// #{ex[:title]}\n" if ex[:title].present? | ||
| example << "#{ex[:verb]} #{ex[:path]}" | ||
| example << "?#{ex[:query]}" unless ex[:query].blank? | ||
| example << "\n" << format_example_data(ex[:request_data]).to_s if ex[:request_data] | ||
| example << "\n" << ex[:code].to_s | ||
| example << "\n" << format_example_data(ex[:response_data]).to_s if ex[:response_data] | ||
| example | ||
| end | ||
|
|
||
| def concern_subst(string) | ||
| return if string.nil? | ||
| if from_concern? | ||
|
|
@@ -225,7 +216,5 @@ def concern_subst(string) | |
| string | ||
| end | ||
| end | ||
|
|
||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -619,16 +619,10 @@ def reload_controllers | |
| describe "examples" do | ||
|
|
||
| it "should be able to load examples from yml file" do | ||
| expect(Apipie.get_method_description(UsersController, :show).examples).to eq [<<EOS1, <<EOS2].map(&:chomp) | ||
| GET /users/14?verbose=true | ||
| 200 | ||
| { | ||
| "name": "Test User" | ||
| } | ||
| EOS1 | ||
| GET /users/15 | ||
| 404 | ||
| EOS2 | ||
| examples = Apipie.get_method_description(UsersController, :show).examples | ||
| expect(examples).to all(be_a(Hash)) | ||
| expect(examples.first[:path]).to eq('/users/14') | ||
| expect(examples.second[:path]).to eq('/users/15') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind adding more assertionas about the examples hash to ensure the expected data are there? |
||
| end | ||
|
|
||
| describe "document" do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing the
@here? Doesn't seem like this could work?