Skip to content

Commit

Permalink
Merge pull request #131 from jamerine/feat-add-operation-id-support
Browse files Browse the repository at this point in the history
added operationId to metadata of request specs
  • Loading branch information
exoego authored Oct 10, 2023
2 parents 74c05d3 + 42d67cc commit 48d556d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 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 @@ -84,7 +86,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
1 change: 1 addition & 0 deletions spec/rails/doc/smart/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ paths:
- message
example:
message: Unauthorized
operationId: table-index
"/tables/{id}":
get:
summary: show
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/rails_smart_merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Small subset of `rails_spec.rb` with slight changes
RSpec.describe 'Tables', type: :request do
describe '#index', openapi: { required_request_params: 'show_columns' } do
describe '#index', openapi: { required_request_params: 'show_columns', operation_id: 'table-index' } do
context it 'returns a list of tables' do
it 'with flat query parameters' do
# These new params replace them in old spec
Expand Down

0 comments on commit 48d556d

Please sign in to comment.