Skip to content

Commit

Permalink
Handle case when conversion is not possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mkon committed Jun 14, 2024
1 parent 4bbd059 commit 369dcc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/openapi_contracts/doc/parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def in_query?
end

def matches?(value)
converted = OpenapiParameters::Converter.convert(value, schema_for_validation)
errors = schemer.validate(converted)
errors = schemer.validate(convert_value(value))
# debug errors.to_a here
errors.none?
end
Expand All @@ -35,6 +34,12 @@ def schema_for_validation

private

def convert_value(original)
OpenapiParameters::Converter.convert(original, schema_for_validation)
rescue StandardError
nil
end

def schemer
@schemer ||= Validators::SchemaValidation.validation_schemer(schema_for_validation)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/openapi_contracts/validators/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,13 @@
expect(subject.call).to contain_exactly '{"page"=>"one"} is not a valid value for the query parameter "settings"'
end
end

context 'when passing non-objects as object' do
let(:path) { '/pets?settings=false' }
let(:required) { false }

it 'has errors' do
expect(subject.call).to contain_exactly '"false" is not a valid value for the query parameter "settings"'
end
end
end

0 comments on commit 369dcc7

Please sign in to comment.