From 4270e148978ac4e7745ac74cf6a0460e7cd95583 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Fri, 11 Jun 2021 12:16:19 -0500 Subject: [PATCH 1/2] Handle schema errors without failing the build --- lib/rspec/openapi/hooks.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rspec/openapi/hooks.rb b/lib/rspec/openapi/hooks.rb index 2b0e5bf9..d9c31c15 100644 --- a/lib/rspec/openapi/hooks.rb +++ b/lib/rspec/openapi/hooks.rb @@ -6,6 +6,7 @@ require 'rspec/openapi/schema_merger' records = [] +records_errors = [] RSpec.configuration.after(:each) do |example| if example.metadata[:type] == :request && example.metadata[:openapi] != false @@ -19,7 +20,21 @@ RSpec::OpenAPI::SchemaFile.new(RSpec::OpenAPI.path).edit do |spec| RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title)) records.each do |record| - RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record)) + begin + RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record)) + rescue => e # e.g. SchemaBuilder raises a NotImplementedError + # NOTE: Don't fail the build + records_errors << [e, record] + end end end + if records_errors.any? + error_message = <<~EOS + RSpec::OpenAPIGot errors building #{records_errors.size} requests + + #{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")} + EOS + colorizer = ::RSpec::Core::Formatters::ConsoleCodes + RSpec.configuration.reporter.message colorizer.wrap(error_message, :failure) + end end From cf1d4ded110491ffe72a646558b6bf2c2f5f432b Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 11 Jun 2021 21:05:28 -0700 Subject: [PATCH 2/2] Update lib/rspec/openapi/hooks.rb --- lib/rspec/openapi/hooks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/openapi/hooks.rb b/lib/rspec/openapi/hooks.rb index d9c31c15..7e4dc255 100644 --- a/lib/rspec/openapi/hooks.rb +++ b/lib/rspec/openapi/hooks.rb @@ -30,7 +30,7 @@ end if records_errors.any? error_message = <<~EOS - RSpec::OpenAPIGot errors building #{records_errors.size} requests + RSpec::OpenAPI got errors building #{records_errors.size} requests #{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")} EOS