diff --git a/lib/rspec/openapi/record.rb b/lib/rspec/openapi/record.rb index 948392d..d336fdc 100644 --- a/lib/rspec/openapi/record.rb +++ b/lib/rspec/openapi/record.rb @@ -14,6 +14,7 @@ :operation_id, # @param [String] - "request-1234" :description, # @param [String] - "returns a status" :security, # @param [Array] - [{securityScheme1: []}] + :deprecated, # @param [Boolean] - true :status, # @param [Integer] - 200 :response_body, # @param [Object] - {"status" => "ok"} :response_headers, # @param [Array] - [["header_key1", "header_value1"], ["header_key2", "header_value2"]] diff --git a/lib/rspec/openapi/record_builder.rb b/lib/rspec/openapi/record_builder.rb index 7523fae..81e11ef 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, operation_id, required_request_params, raw_path_params, description, security = + path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated = extract_request_attributes(request, example) return if RSpec::OpenAPI.ignored_paths.any? { |ignored_path| path.match?(ignored_path) } @@ -32,6 +32,7 @@ def build(context, example:) operation_id: operation_id, description: description, security: security, + deprecated: deprecated, status: response.status, response_body: safe_parse_body(response, response.media_type), response_headers: response_headers, @@ -73,6 +74,7 @@ def extract_request_attributes(request, example) required_request_params = metadata[:required_request_params] || [] security = metadata[:security] description = metadata[:description] || RSpec::OpenAPI.description_builder.call(example) + deprecated = metadata[:deprecated] raw_path_params = request.path_parameters path = request.path if rails? @@ -91,7 +93,7 @@ def extract_request_attributes(request, example) raw_path_params = raw_path_params.slice(*(raw_path_params.keys - RSpec::OpenAPI.ignored_path_params)) end summary ||= "#{request.method} #{path}" - [path, summary, tags, operation_id, required_request_params, raw_path_params, description, security] + [path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated] end def extract_request_response(context) diff --git a/lib/rspec/openapi/schema_builder.rb b/lib/rspec/openapi/schema_builder.rb index 8faadbc..45ca8f6 100644 --- a/lib/rspec/openapi/schema_builder.rb +++ b/lib/rspec/openapi/schema_builder.rb @@ -34,6 +34,7 @@ def build(record) tags: record.tags, operationId: record.operation_id, security: record.security, + deprecated: record.deprecated ? true : nil, parameters: build_parameters(record), requestBody: http_method == 'get' ? nil : build_request_body(record), responses: { diff --git a/spec/rails/doc/openapi.json b/spec/rails/doc/openapi.json index dcce6ad..9eecf8c 100644 --- a/spec/rails/doc/openapi.json +++ b/spec/rails/doc/openapi.json @@ -1126,7 +1126,8 @@ } } } - } + }, + "deprecated": true } } }, diff --git a/spec/rails/doc/openapi.yaml b/spec/rails/doc/openapi.yaml index f77c661..b08aa9b 100644 --- a/spec/rails/doc/openapi.yaml +++ b/spec/rails/doc/openapi.yaml @@ -735,6 +735,7 @@ paths: schema: type: string example: A TEST + deprecated: true components: securitySchemes: SecretApiKeyAuth: diff --git a/spec/requests/rails_spec.rb b/spec/requests/rails_spec.rb index c559ff3..ed90b7b 100644 --- a/spec/requests/rails_spec.rb +++ b/spec/requests/rails_spec.rb @@ -222,7 +222,7 @@ end RSpec.describe 'Extra routes', type: :request do - describe '#test_block' do + describe '#test_block', openapi: { deprecated: true } do it 'returns the block content' do get '/test_block' expect(response.status).to eq(200)