Skip to content

Commit

Permalink
Raise error when loading OpenAPI 3.1 schema (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytjmt authored May 4, 2024
1 parent 68ebcf4 commit dab46d2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/committee/drivers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def self.load_from_data(hash, schema_path = nil, parser_options: {})
return Committee::Drivers::OpenAPI3::Driver.new.parse(openapi)
end

if hash['openapi']&.start_with?('3.1.')
raise OpenAPI3Unsupported.new('Committee does not support OpenAPI 3.1 yet')
end

driver = if hash['swagger'] == '2.0'
Committee::Drivers::OpenAPI2::Driver.new
else
Expand Down
26 changes: 26 additions & 0 deletions test/data/openapi3/3_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
openapi: 3.1.0
info:
version: 1.0.0
title: OpenAPI 3.1 Test
description: A Sample file
paths:
/characters:
get:
description: get characters
parameters:
- name: school_name
in: query
description: school name to filter by
required: false
style: form
schema:
type: array
items:
type: string
responses:
'200':
description: success
content:
application/json:
schema:
type: object
14 changes: 14 additions & 0 deletions test/drivers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
end

it 'fails to load OpenAPI 3.1' do
e = assert_raises(Committee::OpenAPI3Unsupported) do
Committee::Drivers.load_from_file(open_api_3_1_schema_path, parser_options:{strict_reference_validation: true})
end
assert_equal 'Committee does not support OpenAPI 3.1 yet', e.message
end

it 'fails to load OpenAPI 3 with invalid reference' do
parser_options = { strict_reference_validation: true }
assert_raises(OpenAPIParser::MissingReferenceError) do
Expand Down Expand Up @@ -138,6 +145,13 @@
assert_kind_of Committee::Drivers::Schema, s
assert_kind_of Committee::Drivers::HyperSchema::Schema, s
end

it 'fails to load OpenAPI 3.1' do
e = assert_raises(Committee::OpenAPI3Unsupported) do
Committee::Drivers.load_from_data(open_api_3_1_data)
end
assert_equal 'Committee does not support OpenAPI 3.1 yet', e.message
end
end
end

Expand Down
12 changes: 12 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def open_api_3_data
end
end

def open_api_3_1_data
if YAML.respond_to?(:unsafe_load_file)
YAML.unsafe_load_file(open_api_3_1_schema_path)
else
YAML.load_file(open_api_3_1_schema_path)
end
end

def hyper_schema_schema_path
"./test/data/hyperschema/paas.json"
end
Expand All @@ -114,6 +122,10 @@ def open_api_3_0_1_schema_path
"./test/data/openapi3/3_0_1.yaml"
end

def open_api_3_1_schema_path
"./test/data/openapi3/3_1.yaml"
end

def open_api_3_invalid_reference_path
"./test/data/openapi3/invalid_reference.yaml"
end

0 comments on commit dab46d2

Please sign in to comment.