Skip to content

Commit

Permalink
Merge pull request #331 from Pritilender/pritilender/allow-head-metho…
Browse files Browse the repository at this point in the history
…d-in-v3

Allow `HEAD` method in v3
  • Loading branch information
ota42y authored Nov 21, 2021
2 parents 1d9b924 + 60bc86b commit c43ad72
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
10 changes: 2 additions & 8 deletions lib/committee/schema_validator/open_api_3/operation_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ def validate_response_params(status_code, headers, response_data, strict, check_

def validate_request_params(params, headers, validator_option)
ret, err = case request_operation.http_method
when 'get'
when 'get', 'delete', 'head'
validate_get_request_params(params, headers, validator_option)
when 'post'
when 'post', 'put', 'patch'
validate_post_request_params(params, headers, validator_option)
when 'put'
validate_post_request_params(params, headers, validator_option)
when 'patch'
validate_post_request_params(params, headers, validator_option)
when 'delete'
validate_get_request_params(params, headers, validator_option)
else
raise "Committee OpenAPI3 not support #{request_operation.http_method} method"
end
Expand Down
20 changes: 20 additions & 0 deletions test/data/openapi3/normal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ paths:
properties:
integer:
type: integer
parameters:
- name: limit
in: query
description: maximum number of characters
required: false
schema:
type: integer
format: int32
options:
description: preflight request
responses:
'200':
description: success
content:
application/json:
schema:
type: object
properties:
integer:
type: integer

/string_params_coercer:
get:
Expand Down
4 changes: 2 additions & 2 deletions test/middleware/request_validation_open_api_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ def app
@app = new_rack_app(schema: open_api_3_schema)

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

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

describe 'check header' do
Expand Down
22 changes: 22 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 @@ -155,6 +155,28 @@ def operation_object
end
end

describe 'support head method' do
before do
@path = '/characters'
@method = 'head'
end

it 'correct' do
operation_object.validate_request_params({"limit" => "1"}, HEADER, @validator_option)

assert true
end

it 'invalid type' do
e = assert_raises(Committee::InvalidRequest) {
operation_object.validate_request_params({"limit" => "a"}, HEADER, @validator_option)
}

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

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

0 comments on commit c43ad72

Please sign in to comment.