diff --git a/README.md b/README.md index 81a42069..50691af6 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/rspec/openapi/record_builder.rb b/lib/rspec/openapi/record_builder.rb index a4cca6a1..c4f4283d 100644 --- a/lib/rspec/openapi/record_builder.rb +++ b/lib/rspec/openapi/record_builder.rb @@ -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, @@ -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,