Skip to content

Commit

Permalink
Merge pull request #36 from blocknotes/master
Browse files Browse the repository at this point in the history
Customizations via metadata
  • Loading branch information
k0kubun committed Mar 17, 2022
2 parents 4a1cf47 + b9c9cfc commit 366657f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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

0 comments on commit 366657f

Please sign in to comment.