-
Notifications
You must be signed in to change notification settings - Fork 194
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
cast_and_validate purges file upload struct from controller parameters #370
Comments
@superruzafa Same here, looks like the root cause is the same as #92. OpenApiSpex is changing the phoenix params and this causes issues with anything expecting them to be there. |
Looks like when we https://swagger.io/docs/specification/describing-request-body/file-upload/ |
Hey, coming across this a year+ later. Is it possible that the
I am also using a
Does this seem likely, or more likely that I just messed up my |
@petermueller can you test #455 and see if it solves your issue? |
@lucacorti, can do 👍🏻 |
Unfortunately no. Same error :-/ (EDIT: This was after I blew away the deps and _build just in case) Stack
Operation operation :update,
summary: "My Description",
parameters: [MyApp.Schemas.PathParameters.id_param(:id, "My Resource ID")],
request_body: UpdateMyResourceRequest.request_body()
def update(conn, %{id: id}) do
# ...
Schema and custom request_body functiondefmodule MyApp.Schemas.UpdateMyResourceRequest. do
@moduledoc """
The `UpdateMyResourceRequest` `OpenApiSpex` Schema
"""
alias OpenApiSpex.Schema
require OpenApiSpex
OpenApiSpex.schema(%{
description: "Updates my resources",
type: :object,
properties: %{
thing_a: %Schema{
type: :string,
description: "thing_a"
},
thing_b: %Schema{
type: :string,
description: "thing_b"
},
thing_c_dt: %Schema{
type: :string,
description: "thing_c_dt",
format: :"date-time",
nullable: false
},
thing_d_enum: %Schema{
type: :string,
enum: [:asdf, :qwer]
},
# image: %Schema{type: :string, format: :binary}
image: %Schema{
oneOf: [%Schema{type: :string, format: :binary}, Base64ObjectImageUpload]
}
},
example: %{
"thing_a" => "asdf",
"thing_c_dt" => "2021-01-30 15:00:00-04:00",
"image" => "thisistheimagebinary"
}
})
def request_body do
%OpenApiSpex.RequestBody{
description: "Update My Resource",
content: %{
"multipart/form-data" => %OpenApiSpex.MediaType{
schema: __MODULE__,
encoding: %{"image" => %OpenApiSpex.Encoding{contentType: "image/png"}}
},
"application/json" => %OpenApiSpex.MediaType{schema: __MODULE__}
},
required: true
}
end
end |
Hi.
This is more a question than an issue.
In the Phoenix framework, when doing a file upload I used to fetch the
%Plug.Upload
structure from the 2nd parameter passed to the controller's action:I created a spec in order to allow file uploads as noted in similar issues:
After calling
OpenApiSpex.cast_and_validate/4
I noticed that the upload is deleted from the 2nd parameter passed to the controller.I also check that the upload can be accessed from the conn's
body_params
field, but my question is: is there any way to preserve it in the controller's 2nd parameter?Thanks.
The text was updated successfully, but these errors were encountered: