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

New feature: enable example types configuration #32

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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 2 additions & 1 deletion lib/rspec/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/rspec/openapi/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down