From a05157d424feaee0d9bab871d2489c6731ec98dd Mon Sep 17 00:00:00 2001 From: Jason Amerine Date: Thu, 17 Aug 2023 08:47:51 -0400 Subject: [PATCH 1/3] added operationId to metadata of request specs --- lib/rspec/openapi/record.rb | 1 + lib/rspec/openapi/record_builder.rb | 6 ++++-- lib/rspec/openapi/schema_builder.rb | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/rspec/openapi/record.rb b/lib/rspec/openapi/record.rb index cbba7be3..948392de 100644 --- a/lib/rspec/openapi/record.rb +++ b/lib/rspec/openapi/record.rb @@ -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 diff --git a/lib/rspec/openapi/record_builder.rb b/lib/rspec/openapi/record_builder.rb index 54f5fd93..7883ab09 100644 --- a/lib/rspec/openapi/record_builder.rb +++ b/lib/rspec/openapi/record_builder.rb @@ -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) @@ -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, @@ -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) @@ -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) diff --git a/lib/rspec/openapi/schema_builder.rb b/lib/rspec/openapi/schema_builder.rb index 641c27b4..fc542848 100644 --- a/lib/rspec/openapi/schema_builder.rb +++ b/lib/rspec/openapi/schema_builder.rb @@ -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), From d420039f5c038f5cb4c3b014d56f3d279e6f125c Mon Sep 17 00:00:00 2001 From: cyrusg Date: Wed, 4 Oct 2023 11:18:09 -0700 Subject: [PATCH 2/3] Adding test(s) for the new operation_id field. --- spec/requests/rails_smart_merge_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/rails_smart_merge_spec.rb b/spec/requests/rails_smart_merge_spec.rb index eaa5c96a..3a98aba5 100644 --- a/spec/requests/rails_smart_merge_spec.rb +++ b/spec/requests/rails_smart_merge_spec.rb @@ -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 From 42d67cc26d4e912d7334423f312683fcc9ecd1c3 Mon Sep 17 00:00:00 2001 From: cyrusg Date: Wed, 4 Oct 2023 11:29:47 -0700 Subject: [PATCH 3/3] Update expected.yaml to show operationId. --- spec/rails/doc/smart/expected.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/rails/doc/smart/expected.yaml b/spec/rails/doc/smart/expected.yaml index aebfa2cf..41cb1e2d 100644 --- a/spec/rails/doc/smart/expected.yaml +++ b/spec/rails/doc/smart/expected.yaml @@ -86,6 +86,7 @@ paths: - message example: message: Unauthorized + operationId: table-index "/tables/{id}": get: summary: show