Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deprecated attribute #201

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rspec/openapi/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
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, 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) }
Expand All @@ -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,
Expand Down Expand Up @@ -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?
Expand All @@ -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)
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 @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion spec/rails/doc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,8 @@
}
}
}
}
},
"deprecated": true
}
}
},
Expand Down
1 change: 1 addition & 0 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ paths:
schema:
type: string
example: A TEST
deprecated: true
components:
securitySchemes:
SecretApiKeyAuth:
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down