Skip to content

Commit

Permalink
Fix: params is not the same in RESTful APIs with different verbs
Browse files Browse the repository at this point in the history
  • Loading branch information
khiav reoy committed Apr 15, 2020
1 parent 81e5c56 commit 0974a4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
7 changes: 4 additions & 3 deletions lib/rspec_api_documentation/views/api_blueprint_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ def sections
super.map do |section|
routes = section[:examples].group_by { |e| "#{e.route_uri}#{e.route_optionals}#{e.route_name}" }.map do |route, examples|
attrs = fields(:attributes, examples)
params = fields(:parameters, examples)

methods = examples.group_by(&:http_method).map do |http_method, examples|
params = fields(:parameters, examples)

{
"has_parameters?".to_sym => params.size > 0,
http_method: http_method,
parameters: params,
description: examples.first.respond_to?(:action_name) && examples.first.action_name,
examples: examples
}
end

{
"has_attributes?".to_sym => attrs.size > 0,
"has_parameters?".to_sym => params.size > 0,
route: format_route(examples[0]),
route_name: examples[0][:route_name],
attributes: attrs,
parameters: params,
http_methods: methods
}
end
Expand Down
26 changes: 13 additions & 13 deletions templates/rspec_api_documentation/api_blueprint_index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ description: {{ description }}

explanation: {{ explanation }}
{{/ explanation }}
{{# has_parameters? }}
{{# has_attributes? }}

+ Parameters
{{# parameters }}
+ Attributes (object)
{{# attributes }}
+ {{ name }}{{# example }}: {{ example }}{{/ example }}{{# properties_description }} ({{ properties_description }}){{/ properties_description }}{{# description }} - {{ description }}{{/ description }}
{{# has_default?}}
+ Default: `{{default}}`
Expand All @@ -40,12 +40,15 @@ explanation: {{ explanation }}
{{# annotations }}
{{ . }}
{{/ annotations }}
{{/ parameters }}
{{/ has_parameters? }}
{{# has_attributes? }}
{{/ attributes }}
{{/ has_attributes? }}
{{# http_methods }}

+ Attributes (object)
{{# attributes }}
### {{ description }} [{{ http_method }}]
{{# has_parameters? }}

+ Parameters
{{# parameters }}
+ {{ name }}{{# example }}: {{ example }}{{/ example }}{{# properties_description }} ({{ properties_description }}){{/ properties_description }}{{# description }} - {{ description }}{{/ description }}
{{# has_default?}}
+ Default: `{{default}}`
Expand All @@ -59,11 +62,8 @@ explanation: {{ explanation }}
{{# annotations }}
{{ . }}
{{/ annotations }}
{{/ attributes }}
{{/ has_attributes? }}
{{# http_methods }}

### {{ description }} [{{ http_method }}]
{{/ parameters }}
{{/ has_parameters? }}
{{# examples }}
{{# requests }}
{{# has_request? }}
Expand Down

0 comments on commit 0974a4e

Please sign in to comment.