From 5b2850797f68fd7f8e50135d4cbeab3ef6f7c2b4 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Wed, 11 Sep 2024 14:25:08 +0300 Subject: [PATCH] Fixes YAML parsing issue when the file exists but empty --- lib/rspec/openapi/schema_file.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rspec/openapi/schema_file.rb b/lib/rspec/openapi/schema_file.rb index 53f14f9..8c1f62e 100644 --- a/lib/rspec/openapi/schema_file.rb +++ b/lib/rspec/openapi/schema_file.rb @@ -24,7 +24,11 @@ def edit(&block) def read return {} unless File.exist?(@path) - RSpec::OpenAPI::KeyTransformer.symbolize(YAML.safe_load(File.read(@path))) # this can also parse JSON + content = YAML.safe_load(File.read(@path)) # This can also parse JSON + + return {} if content.nil? + + RSpec::OpenAPI::KeyTransformer.symbolize(content) end # @param [Hash] spec