Skip to content

Commit

Permalink
Allow regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Mar 8, 2024
1 parent d2691e1 commit 13fd923
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/openapi/record_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion spec/integration_tests/rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/.*$")]

Check notice

Code scanning / Rubocop

Checks if uses of quotes match the configured preference. Note test

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
RSpec::OpenAPI.comment = <<~COMMENT
This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
Expand Down

0 comments on commit 13fd923

Please sign in to comment.