support format: binary
Plan
OpenAPI 3.0.3 support fomat: binary so we should support it.
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#data-types
Rack set file as Rack::Multipart::UploadedFile so we should check it in string validator.
https://github.com/ota42y/openapi_parser/blob/master/lib/openapi_parser/schema_validators/string_validator.rb#L10
Other
related https://github.com/interagent/committee/issues/255#issuecomment-699821755
@ota42y wanted to ask what the status on this is. Is it in production already? I still get the same "expected string but received Hash" validation error for file uploads (with type: string and format: binary)
Sorry, we are not currently implementing it, and we have no plans to do so for the time being.
Sorry for question: are there any workaround for this? For now it's impossible to validate submitted via form data file :/
At the moment there are none. However, if there is an error, we would like to have some workaround (no verification, but no error either).
This code/patch works for me:
module StringValidatorPatch
def coerce_and_validate(value, schema, **_keyword_args)
# Diff:
# :- return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(String)
#
# :+
if !value.is_a?(String)
if schema.format == 'binary'
# Fix: in tests rack uploaded file not converts automatically (committee bug)
if value[:tempfile]
return [ActionDispatch::Http::UploadedFile.new(value), nil]
else
return [value, nil]
end
else
return OpenAPIParser::ValidateError.build_error_result(value, schema)
end
end
# End of diff
value, err = check_enum_include(value, schema)
return [nil, err] if err
value, err = pattern_validate(value, schema)
return [nil, err] if err
value, err = validate_max_min_length(value, schema)
return [nil, err] if err
value, err = validate_email_format(value, schema)
return [nil, err] if err
value, err = validate_uuid_format(value, schema)
return [nil, err] if err
value, err = validate_date_format(value, schema)
return [nil, err] if err
value, err = validate_datetime_format(value, schema)
return [nil, err] if err
[value, nil]
end
end
class OpenAPIParser::SchemaValidator::StringValidator
prepend StringValidatorPatch
end