From 38d1d912a99954738d4bd01f35a804c10174c92c Mon Sep 17 00:00:00 2001 From: Justin Schier Date: Mon, 22 Nov 2021 13:48:09 -0500 Subject: [PATCH 1/2] New feature: enable example types configuration --- lib/rspec/openapi.rb | 3 ++- lib/rspec/openapi/hooks.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/rspec/openapi.rb b/lib/rspec/openapi.rb index 5e62936a..6655c683 100644 --- a/lib/rspec/openapi.rb +++ b/lib/rspec/openapi.rb @@ -9,8 +9,9 @@ module RSpec::OpenAPI @application_version = '1.0.0' @request_headers = [] @server_urls = [] + @example_types = %i[request] class << self - attr_accessor :path, :comment, :enable_example, :description_builder, :application_version, :request_headers, :server_urls + attr_accessor :path, :comment, :enable_example, :description_builder, :application_version, :request_headers, :server_urls, :example_types end end diff --git a/lib/rspec/openapi/hooks.rb b/lib/rspec/openapi/hooks.rb index 5e536c43..282e3833 100644 --- a/lib/rspec/openapi/hooks.rb +++ b/lib/rspec/openapi/hooks.rb @@ -9,7 +9,7 @@ records_errors = [] RSpec.configuration.after(:each) do |example| - if example.metadata[:type] == :request && example.metadata[:openapi] != false + if RSpec::OpenAPI.example_types.include?(example.metadata[:type]) && example.metadata[:openapi] != false record = RSpec::OpenAPI::RecordBuilder.build(self, example: example) records << record if record end @@ -31,7 +31,7 @@ if records_errors.any? error_message = <<~EOS RSpec::OpenAPI got errors building #{records_errors.size} requests - + #{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")} EOS colorizer = ::RSpec::Core::Formatters::ConsoleCodes From af8027a58a88ef56942332cd1d345b5e1465366a Mon Sep 17 00:00:00 2001 From: Justin Schier Date: Mon, 22 Nov 2021 13:56:55 -0500 Subject: [PATCH 2/2] Add documentation for example_types configuration --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c80fb8ee..bd962b61 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,9 @@ EOS # Generate a custom description, given an RSpec example RSpec::OpenAPI.description_builder = -> (example) { example.description } + +# Change the example type(s) that will generate schema +RSpec::OpenAPI.example_types = %i[request] ``` ### How can I add information which can't be generated from RSpec?