Skip to content
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ RSpec.describe '/resources', type: :request do
end
```

## Customizations

Some examples' attributes can be overwritten via RSpec metadata options. Example:

```rb
describe 'GET /api/v1/posts', openapi: {
summary: 'list all posts',
description: 'list all posts ordered by pub_date',
tags: %w[v1 posts],
} do
# ...
end
```

**NOTE**: `description` key will override also the one provided by `RSpec::OpenAPI.description_builder` method.

## Links

Existing RSpec plugins which have OpenAPI integration:
Expand Down
8 changes: 5 additions & 3 deletions lib/rspec/openapi/record_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def build(context, example:)
headers_arr << [header, header_value] if header_value
end

metadata_options = example.metadata[:openapi] || {}

RSpec::OpenAPI::Record.new(
method: request.request_method,
path: path,
Expand All @@ -48,9 +50,9 @@ def build(context, example:)
request_params: raw_request_params(request),
request_content_type: request.media_type,
request_headers: request_headers,
summary: summary,
tags: tags,
description: RSpec::OpenAPI.description_builder.call(example),
summary: metadata_options[:summary] || summary,
tags: metadata_options[:tags] || tags,
description: metadata_options[:description] || RSpec::OpenAPI.description_builder.call(example),
status: response.status,
response_body: response_body,
response_content_type: response.media_type,
Expand Down