Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure which path params to ignore #150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ RSpec::OpenAPI.description_builder = -> (example) { example.description }

# Change the example type(s) that will generate schema
RSpec::OpenAPI.example_types = %i[request]

# Configure which path params to ignore
# :controller and :action always exist. :format is added when routes is configured as such.
RSpec::OpenAPI.ignored_path_params = %i[controller action format]

```

### Can I use rspec-openapi with `$ref` to minimize duplication of schema?
Expand Down
4 changes: 3 additions & 1 deletion lib/rspec/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module RSpec::OpenAPI
@example_types = %i[request]
@response_headers = []
@path_records = Hash.new { |h, k| h[k] = [] }
@ignored_path_params = %i[controller action format]

class << self
attr_accessor :path,
Expand All @@ -39,6 +40,7 @@ class << self
:security_schemes,
:example_types,
:response_headers,
:path_records
:path_records,
:ignored_path_params
end
end
2 changes: 1 addition & 1 deletion lib/rspec/openapi/record_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def extract_request_attributes(request, example)
tags ||= [route.requirements[:controller]&.classify].compact
# :controller and :action always exist. :format is added when routes is configured as such.
# TODO: Use .except(:controller, :action, :format) when we drop support for Ruby 2.x
raw_path_params = raw_path_params.slice(*(raw_path_params.keys - %i[controller action format]))
raw_path_params = raw_path_params.slice(*(raw_path_params.keys - RSpec::OpenAPI.ignored_path_params))
end
summary ||= "#{request.method} #{path}"
[path, summary, tags, operation_id, required_request_params, raw_path_params, description, security]
Expand Down
Loading