From 5555edc59fa3bb6074810e1a5687411847f9f734 Mon Sep 17 00:00:00 2001 From: Jay Danielian Date: Mon, 26 Aug 2019 22:25:53 -0400 Subject: [PATCH] Only automatically save examples if examples are not given explicitly in the spec itself --- rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb b/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb index 58fc489..b0efcbe 100644 --- a/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb +++ b/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb @@ -238,7 +238,9 @@ module OpenApi if body_parameter && respond_to?(body_parameter[:name]) && example.metadata[:operation][:requestBody][:content]['application/json'] # save response examples by default - example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) } unless response.body.to_s.empty? + if example.metadata[:response][:examples].nil? || example.metadata[:response][:examples].empty? + example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) } unless response.body.to_s.empty? + end # save request examples using the let(:param_name) { REQUEST_BODY_HASH } syntax in the test if response.code.to_s =~ /^2\d{2}$/