-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support format: binary #108
Comments
@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. |
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 |
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 interagent/committee#255 (comment)
The text was updated successfully, but these errors were encountered: