Skip to content

Commit

Permalink
added operationId to metadata of request specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamerine committed Aug 17, 2023
1 parent 6a1fbf4 commit a05157d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/rspec/openapi/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:request_headers, # @param [Array] - [["header_key1", "header_value1"], ["header_key2", "header_value2"]]
:summary, # @param [String] - "v1/statuses #show"
:tags, # @param [Array] - ["Status"]
:operation_id, # @param [String] - "request-1234"
:description, # @param [String] - "returns a status"
:security, # @param [Array] - [{securityScheme1: []}]
:status, # @param [Integer] - 200
Expand Down
6 changes: 4 additions & 2 deletions lib/rspec/openapi/record_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def build(context, example:)
request, response = extract_request_response(context)
return if request.nil?

path, summary, tags, required_request_params, raw_path_params, description, security =
path, summary, tags, operation_id, required_request_params, raw_path_params, description, security =
extract_request_attributes(request, example)

request_headers, response_headers = extract_headers(request, response)
Expand All @@ -27,6 +27,7 @@ def build(context, example:)
request_headers: request_headers,
summary: summary,
tags: tags,
operation_id: operation_id,
description: description,
security: security,
status: response.status,
Expand Down Expand Up @@ -63,6 +64,7 @@ def extract_request_attributes(request, example)
metadata = example.metadata[:openapi] || {}
summary = metadata[:summary]
tags = metadata[:tags]
operation_id = metadata[:operation_id]
required_request_params = metadata[:required_request_params] || []
security = metadata[:security]
description = metadata[:description] || RSpec::OpenAPI.description_builder.call(example)
Expand All @@ -78,7 +80,7 @@ def extract_request_attributes(request, example)
raw_path_params = raw_path_params.slice(*(raw_path_params.keys - %i[controller action format]))
end
summary ||= "#{request.method} #{path}"
[path, summary, tags, required_request_params, raw_path_params, description, security]
[path, summary, tags, operation_id, required_request_params, raw_path_params, description, security]
end

def extract_request_response(context)
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def build(record)
record.http_method.downcase => {
summary: record.summary,
tags: record.tags,
operationId: record.operation_id,
security: record.security,
parameters: build_parameters(record),
requestBody: build_request_body(record),
Expand Down

0 comments on commit a05157d

Please sign in to comment.