-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add support for 'multipart/form-data' file upload #255
Comments
I faced to same problem too. module StringValidatorPatch
def coerce_and_validate(value, schema, **_keyword_args)
# change this
# https://github.com/ota42y/openapi_parser/blob/61874f0190a86c09bdfb78de5f51cfb6ae16068b/lib/openapi_parser/schema_validators/string_validator.rb#L11
unless value.is_a?(String)
return OpenAPIParser::ValidateError.build_error_result(value, schema) if schema.format != 'binary'
end
# --- end
value, err = check_enum_include(value, schema)
return [nil, err] if err
value, err = pattern_validate(value, schema)
return [nil, err] if err
unless @datetime_coerce_class.nil?
value, err = coerce_date_time(value, schema)
return [nil, err] if err
end
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, nil]
end
end
class OpenAPIParser::SchemaValidator::StringValidator
prepend StringValidatorPatch
end |
The actual version of patch (maybe, not sure, but works for my test suite): 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 |
We have no plans to fix it at this time (not that we don't want to, just that we don't have time to deal with it). |
I'm attempting to describe file upload, according to swagger docs for file-upload we should define the file as type string with the format of binary.
so my openapi for this request looks like:
However by the time this gets to the committee middleware rack has exploded the file to a hash
so we end up with an error like:
I was looking at test/request_unpacker_test.rb but I do not see how to handle this situation. What am I missing?
The text was updated successfully, but these errors were encountered: