From 4c27430cc16b4a4c37660a089e4e280817c2423f Mon Sep 17 00:00:00 2001 From: Brandur Date: Sat, 4 May 2024 19:41:05 +0200 Subject: [PATCH] Error on anything above OpenAPI 3.1 as well + changelog Follows up #418 with a small future compatibility change so that if an OpenAPI version is anything equal or greater than 3.1 the error is produced. Also, add a changelog entry about it. --- lib/committee/drivers.rb | 6 ++++-- test/drivers_test.rb | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/committee/drivers.rb b/lib/committee/drivers.rb index 0edc6be4..63223f24 100644 --- a/lib/committee/drivers.rb +++ b/lib/committee/drivers.rb @@ -70,8 +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') + if (version = hash['openapi']) + if Gem::Version.new(version) >= Gem::Version.new("3.1") + raise OpenAPI3Unsupported.new('Committee does not support OpenAPI 3.1+ yet') + end end driver = if hash['swagger'] == '2.0' diff --git a/test/drivers_test.rb b/test/drivers_test.rb index e322ac15..b77c5cdd 100644 --- a/test/drivers_test.rb +++ b/test/drivers_test.rb @@ -48,11 +48,11 @@ assert_kind_of Committee::Drivers::OpenAPI3::Schema, s end - it 'fails to load OpenAPI 3.1' do + 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 + assert_equal 'Committee does not support OpenAPI 3.1+ yet', e.message end it 'fails to load OpenAPI 3 with invalid reference' do @@ -146,11 +146,11 @@ assert_kind_of Committee::Drivers::HyperSchema::Schema, s end - it 'fails to load OpenAPI 3.1' do + 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 + assert_equal 'Committee does not support OpenAPI 3.1+ yet', e.message end end end