Skip to content

Commit

Permalink
Merge pull request interagent#344 from flowdgmbh/master
Browse files Browse the repository at this point in the history
Support Http OPTIONS method
  • Loading branch information
ota42y authored Dec 19, 2021
2 parents 01e5077 + 72b9629 commit 0acc4ac
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def validate_request_params(params, headers, validator_option)
ret, err = case request_operation.http_method
when 'get', 'delete', 'head'
validate_get_request_params(params, headers, validator_option)
when 'post', 'put', 'patch'
when 'post', 'put', 'patch', 'options'
validate_post_request_params(params, headers, validator_option)
else
raise "Committee OpenAPI3 not support #{request_operation.http_method} method"
Expand Down
26 changes: 26 additions & 0 deletions test/data/openapi3/normal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,26 @@ paths:
properties:
string:
type: string
options:
description: validate options metodhd
requestBody:
content:
application/json:
schema:
type: object
properties:
integer:
type: integer
responses:
'200':
description: success
content:
application/json:
schema:
type: object
properties:
string:
type: string

/validate_content_types:
post:
Expand Down Expand Up @@ -570,6 +590,12 @@ paths:
responses:
'200':
$ref: '#/components/responses/header_integer_required'
options:
parameters:
- $ref: '#/components/parameters/header_integer_required'
responses:
'200':
$ref: '#/components/responses/header_integer_required'

/get_endpoint_with_requered_parameter:
get:
Expand Down
12 changes: 1 addition & 11 deletions test/middleware/request_validation_open_api_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,6 @@ def app
assert_equal 204, last_response.status
end

it "OpenAPI3 raise not support method" do
@app = new_rack_app(schema: open_api_3_schema)

e = assert_raises(RuntimeError) {
options "/characters", {}
}

assert_equal 'Committee OpenAPI3 not support options method', e.message
end

describe 'check header' do
[
{ check_header: true, description: 'valid value', value: 1, expected: { status: 200 } },
Expand All @@ -482,7 +472,7 @@ def app
value = h[:value]
expected = h[:expected]
describe "when #{check_header}" do
%w(get post put patch delete).each do |method|
%w(get post put patch delete options).each do |method|
describe method do
describe description do
it (expected[:error].nil? ? 'should pass' : 'should fail') do
Expand Down
2 changes: 1 addition & 1 deletion test/middleware/response_validation_open_api_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def app
header = h[:header]
expected = h[:expected]
describe "when #{check_header}" do
%w(get post put patch delete).each do |method|
%w(get post put patch delete options).each do |method|
describe method do
describe description do
if expected[:error].nil?
Expand Down
13 changes: 13 additions & 0 deletions test/schema_validator/open_api_3/operation_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ def operation_object
end
end

it 'support options method' do
@method = "options"
operation_object.validate_request_params({"integer" => 1}, HEADER, @validator_option)

e = assert_raises(Committee::InvalidRequest) {
operation_object.validate_request_params({"integer" => "str"}, HEADER, @validator_option)
}

assert_match(/expected integer, but received String: "str"/i, e.message)
assert_kind_of(OpenAPIParser::OpenAPIError, e.original_error)
end


describe '#content_types' do
it 'returns supported content types' do
@path = '/validate_content_types'
Expand Down

0 comments on commit 0acc4ac

Please sign in to comment.