From 82a5eea386861c9a89b698913db51938313baf67 Mon Sep 17 00:00:00 2001 From: khiav reoy Date: Thu, 16 Apr 2020 05:45:09 +0800 Subject: [PATCH] Fix: params is not the same in RESTful APIs with different verbs --- .../views/api_blueprint_index.rb | 7 ++--- .../api_blueprint_index.mustache | 26 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/rspec_api_documentation/views/api_blueprint_index.rb b/lib/rspec_api_documentation/views/api_blueprint_index.rb index ef42c1fa..2a343c85 100644 --- a/lib/rspec_api_documentation/views/api_blueprint_index.rb +++ b/lib/rspec_api_documentation/views/api_blueprint_index.rb @@ -10,11 +10,14 @@ 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 } @@ -22,11 +25,9 @@ def sections { "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 diff --git a/templates/rspec_api_documentation/api_blueprint_index.mustache b/templates/rspec_api_documentation/api_blueprint_index.mustache index 8100200e..d0111485 100644 --- a/templates/rspec_api_documentation/api_blueprint_index.mustache +++ b/templates/rspec_api_documentation/api_blueprint_index.mustache @@ -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}}` @@ -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}}` @@ -59,11 +62,8 @@ explanation: {{ explanation }} {{# annotations }} {{ . }} {{/ annotations }} -{{/ attributes }} -{{/ has_attributes? }} -{{# http_methods }} - -### {{ description }} [{{ http_method }}] +{{/ parameters }} +{{/ has_parameters? }} {{# examples }} {{# requests }} {{# has_request? }}