-
Notifications
You must be signed in to change notification settings - Fork 7
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
Uploading file ActiveStorage #16
Comments
Hey, @ShonRepo! I just released a new version of gem with a limited support of binary files validation. Here is an example: # docs/openapi.yaml
#...
paths:
/upload:
post:
summary: Example of Active Storage upload
requestBody:
content:
multipart/form-data:
schema:
type: object
required: [file]
properties:
file: {}
responses:
"200":
description: successful operation
"422":
$ref: '#/components/responses/ErrorResponse' To work with # spec/rails_helper.rb
#...
Skooma::BodyParsers.register("multipart/form-data", ->(body, headers:) do
info = Rack::Multipart::Parser.parse(
StringIO.new(body),
headers["Content-Length"].to_i,
headers["Content-Type"],
->(*) { String.new },
Rack::Multipart::Parser::BUFSIZE,
Rack::Utils.default_query_parser,
)
info.params
end) Now it's possible to validate requests: # spec/requests/upload_spec.rb
# ...
describe "POST /upload" do
subject { post("/upload", params:) }
let(:test_file) { file_fixture("image.jpeg") }
let(:file) { fixture_file_upload(test_file, "image/jpeg") }
let(:params) { {file:} }
it { is_expected.to conform_schema(200) }
context "without file" do
let(:file) { nil }
it { is_expected.to conform_response_schema(422) }
end
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey!
If I upload a file using the
as: :json
post method, I get this errorbut, not use
as: :json
, the file is loading successfully, but if there is a body required parameter in the openapi schema, then I get the errorbody id required
code:
The text was updated successfully, but these errors were encountered: