From 7b5876c178ccb13356249ab08232079c572c47da Mon Sep 17 00:00:00 2001 From: Klaus Meyer Date: Thu, 22 Aug 2024 10:00:45 +0200 Subject: [PATCH] allow json_schemer 2.3.x --- .github/workflows/main.yml | 4 ++-- openapi_contracts.gemspec | 2 +- .../validators/request_body_spec.rb | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9e5782..e8d6e7d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: strategy: fail-fast: false matrix: - activesupport: ['6.1', '7.0', '7.1'] - json_schemer: ['2.0', '2.1'] + activesupport: ['6.1', '7.0', '7.1', '7.2'] + json_schemer: ['2.0', '2.1', '2.2', '2.3'] ruby: ['3.1', '3.2', '3.3'] steps: - uses: actions/checkout@v3 diff --git a/openapi_contracts.gemspec b/openapi_contracts.gemspec index 45c4a58..9836c9e 100644 --- a/openapi_contracts.gemspec +++ b/openapi_contracts.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = Dir['lib/**/*', 'README.md'] s.add_dependency 'activesupport', '>= 6.1', '< 8' - s.add_dependency 'json_schemer', '>= 2', '< 2.2' + s.add_dependency 'json_schemer', '>= 2', '< 2.4' s.add_dependency 'openapi_parameters', '>= 0.3.3', '< 0.4' s.add_dependency 'rack', '>= 2.0.0' diff --git a/spec/openapi_contracts/validators/request_body_spec.rb b/spec/openapi_contracts/validators/request_body_spec.rb index 5728dc2..6c6cb68 100644 --- a/spec/openapi_contracts/validators/request_body_spec.rb +++ b/spec/openapi_contracts/validators/request_body_spec.rb @@ -28,9 +28,19 @@ } end + let(:error_disallowed_additional_property) do + # The exact wording of the error messages changed after version 2.2 of json_schemer gem + # https://github.com/davishmcclurg/json_schemer/compare/v2.1.1...v2.3.0#diff-fbfde32a749d1a55202956b04373a19b8612259773aff9e2dadd525215c4a7f5R303 + if Gem.loaded_specs['json_schemer'].version < Gem::Version.create('2.2') + 'object property at `/data/id` is not defined and schema does not allow additional properties' + else + 'object property at `/data/id` is a disallowed additional property' + end + end + it 'returns all errors' do expect(subject.call).to contain_exactly( - 'object property at `/data/id` is not defined and schema does not allow additional properties', + error_disallowed_additional_property, 'null at `/data/type` is not a string', 'object at `/data/attributes` is missing required properties: email' )