From cea4a3525a1ef09f00a43e7ff028a159b02b2ce8 Mon Sep 17 00:00:00 2001 From: cyrusg Date: Thu, 28 Sep 2023 13:45:37 -0700 Subject: [PATCH 1/2] Allow for path-based configuration overrides. --- lib/rspec/openapi.rb | 4 +++- lib/rspec/openapi/result_recorder.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rspec/openapi.rb b/lib/rspec/openapi.rb index c91b054e..f2f3a813 100644 --- a/lib/rspec/openapi.rb +++ b/lib/rspec/openapi.rb @@ -26,6 +26,7 @@ module RSpec::OpenAPI @example_types = %i[request] @response_headers = [] @path_records = Hash.new { |h, k| h[k] = [] } + @config_filename = 'rspec_openapi.rb' class << self attr_accessor :path, @@ -39,6 +40,7 @@ class << self :security_schemes, :example_types, :response_headers, - :path_records + :path_records, + :config_filename end end diff --git a/lib/rspec/openapi/result_recorder.rb b/lib/rspec/openapi/result_recorder.rb index 1ff6b560..1b3aa0b8 100644 --- a/lib/rspec/openapi/result_recorder.rb +++ b/lib/rspec/openapi/result_recorder.rb @@ -9,6 +9,10 @@ def initialize(path_records) def record_results! title = File.basename(Dir.pwd) @path_records.each do |path, records| + # Look for a path-specific config file and run it. + config_file = File.join(File.dirname(path), RSpec::OpenAPI.config_filename) + eval(File.read(config_file)) if File.exist?(config_file) + RSpec::OpenAPI::SchemaFile.new(path).edit do |spec| schema = RSpec::OpenAPI::DefaultSchema.build(title) schema[:info].merge!(RSpec::OpenAPI.info) From 447561f628fbaafbf7f34dcdee94e949fe88587e Mon Sep 17 00:00:00 2001 From: cyrusg Date: Fri, 29 Sep 2023 09:58:19 -0700 Subject: [PATCH 2/2] config_filename needs to be accessible to the ResultRecorder. --- lib/rspec/openapi.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rspec/openapi.rb b/lib/rspec/openapi.rb index f2f3a813..a5ea9cb8 100644 --- a/lib/rspec/openapi.rb +++ b/lib/rspec/openapi.rb @@ -26,6 +26,8 @@ module RSpec::OpenAPI @example_types = %i[request] @response_headers = [] @path_records = Hash.new { |h, k| h[k] = [] } + + # This is the configuraion override file name we look for within each path. @config_filename = 'rspec_openapi.rb' class << self @@ -40,7 +42,8 @@ class << self :security_schemes, :example_types, :response_headers, - :path_records, - :config_filename + :path_records + + attr_reader :config_filename end end