diff --git a/README.md b/README.md index c5d608b..dddb137 100644 --- a/README.md +++ b/README.md @@ -185,9 +185,11 @@ RSpec::OpenAPI.example_types = %i[request] RSpec::OpenAPI.ignored_path_params = %i[controller action format] # Configure which paths to ignore. -# In a complex test case, you may need to call an API, which you want to exclude from OpenAPI schema. +# You can exclude some specs via `openapi: false`. +# But, in a complex API usage scenario, you may need to include spec itself, but exclude some private paths. # In that case, you can specify the paths to ignore. -RSpec::OpenAPI.ignored_paths = ["/foo/bar"] +# String or Regexp is acceptable. +RSpec::OpenAPI.ignored_paths = ["/admin/full/path/", Regexp.new("^/_internal/")] ``` ### Can I use rspec-openapi with `$ref` to minimize duplication of schema? diff --git a/lib/rspec/openapi/record_builder.rb b/lib/rspec/openapi/record_builder.rb index 0bd3998..ea243b8 100644 --- a/lib/rspec/openapi/record_builder.rb +++ b/lib/rspec/openapi/record_builder.rb @@ -14,7 +14,7 @@ def build(context, example:) path, summary, tags, operation_id, required_request_params, raw_path_params, description, security = extract_request_attributes(request, example) - return if RSpec::OpenAPI.ignored_paths.include?(path) + return if RSpec::OpenAPI.ignored_paths.any? { |ignored_path| path.match?(ignored_path) } request_headers, response_headers = extract_headers(request, response) diff --git a/spec/integration_tests/rails_test.rb b/spec/integration_tests/rails_test.rb index 9d2bc4d..c3bac04 100644 --- a/spec/integration_tests/rails_test.rb +++ b/spec/integration_tests/rails_test.rb @@ -11,7 +11,7 @@ RSpec::OpenAPI.request_headers = %w[X-Authorization-Token] RSpec::OpenAPI.response_headers = %w[X-Cursor] RSpec::OpenAPI.path = File.expand_path("../rails/doc/openapi.#{ENV.fetch('OPENAPI_OUTPUT', nil)}", __dir__) -RSpec::OpenAPI.ignored_paths = ["/admin/masters/extensions"] +RSpec::OpenAPI.ignored_paths = [Regexp.new("/admin/.*$")] RSpec::OpenAPI.comment = <<~COMMENT This file is auto-generated by rspec-openapi /~https://github.com/k0kubun/rspec-openapi