Skip to content
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
4 changes: 4 additions & 0 deletions lib/committee/schema_validator/open_api_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def link_exist?
!@operation_object.nil?
end

# Expose the operation matched for the request, or nil if none matched
# @return [Committee::SchemaValidator::OpenAPI3::OperationWrapper, nil]
attr_reader :operation_object

private

attr_reader :validator_option
Expand Down
27 changes: 27 additions & 0 deletions test/schema_validator/open_api_3_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "test_helper"

describe Committee::SchemaValidator::OpenAPI3 do
before do
@router = open_api_3_schema.build_router(schema: open_api_3_schema)
end

def validator_for(path, method)
request = Rack::Request.new({ "REQUEST_METHOD" => method, "PATH_INFO" => path, "rack.input" => StringIO.new("") })
@router.build_schema_validator(request)
end

describe "#operation_object" do
it "returns the matched operation wrapper" do
operation_object = validator_for("/validate", "POST").operation_object

assert_kind_of Committee::SchemaValidator::OpenAPI3::OperationWrapper, operation_object
assert_equal "/validate", operation_object.original_path
end

it "returns nil when the request matches no operation" do
assert_nil validator_for("/no-such-path", "GET").operation_object
end
end
end