Skip to content

Commit

Permalink
Skip the validation against the binary string
Browse files Browse the repository at this point in the history
Ref ota42y#148

Signed-off-by: moznion <[email protected]>
  • Loading branch information
moznion committed Feb 21, 2025
1 parent 95f66e1 commit 3b5467a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/openapi_parser/schema_validator/string_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ def initialize(validator, coerce_value, datetime_coerce_class)
end

def coerce_and_validate(value, schema, **_keyword_args)
return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(String)
unless value.kind_of?(String)
# Skip validation if the format is `binary`, even if the value is not an actual string.
# ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#data-types
if schema.format == 'binary'
# TODO:
# It would be better to check whether the value is an instance of `Rack::Multipart::UploadFile`,
# `ActionDispatch::Http::UploadedFile`, or another similar class.
return [value, nil]
end

return OpenAPIParser::ValidateError.build_error_result(value, schema)
end

value, err = check_enum_include(value, schema)
return [nil, err] if err
Expand Down
20 changes: 20 additions & 0 deletions spec/openapi_parser/schema_validator/string_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,24 @@
end
end
end

describe 'validate binary format' do
subject { OpenAPIParser::SchemaValidator.validate(params, target_schema, options) }

let(:replace_schema) do
{
binary: {
type: 'string',
format: 'binary',
},
}
end

context 'correct' do
context 'arbitrary object except string' do
let(:params) { { 'binary' => ['b', 'i', 'n', 'a', 'r', 'y'] } }
it { expect(subject).to eq({ 'binary' => ['b', 'i', 'n', 'a', 'r', 'y'] }) }
end
end
end
end

0 comments on commit 3b5467a

Please sign in to comment.