From a61237e5f41332e59a6061a7d8d6b8f28aa10357 Mon Sep 17 00:00:00 2001 From: hehe1111 <2908749709@qq.com> Date: Sun, 16 Jul 2023 16:33:44 +0800 Subject: [PATCH] Add parameter enums and defaults to HTML example --- lib/rspec_api_documentation/example.rb | 8 ++++++++ .../rspec_api_documentation/html_example.mustache | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/rspec_api_documentation/example.rb b/lib/rspec_api_documentation/example.rb index ba8f0ad7..fb97a1b5 100644 --- a/lib/rspec_api_documentation/example.rb +++ b/lib/rspec_api_documentation/example.rb @@ -38,6 +38,14 @@ def has_parameters? respond_to?(:parameters) && parameters.present? end + def has_enum? + respond_to?(:parameters) && parameters.present? && parameters.any? { |i| i[:enum] } + end + + def has_default? + respond_to?(:parameters) && parameters.present? && parameters.any? { |i| i[:default] } + end + def has_attributes? respond_to?(:attributes) && attributes.present? end diff --git a/templates/rspec_api_documentation/html_example.mustache b/templates/rspec_api_documentation/html_example.mustache index 518a730e..f3c7a519 100644 --- a/templates/rspec_api_documentation/html_example.mustache +++ b/templates/rspec_api_documentation/html_example.mustache @@ -31,6 +31,12 @@ Name Description + {{# has_enum? }} + Accepted values + {{/ has_enum? }} + {{# has_default? }} + Default + {{/ has_default? }} @@ -47,6 +53,12 @@ {{ description }} + {{# has_enum? }} + {{ enum }} + {{/ has_enum? }} + {{# has_default? }} + {{ default }} + {{/ has_default? }} {{/ parameters }}