Skip to content
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

multipart/form-data - value must be an object #1169

Closed
Ol1BoT opened this issue Aug 2, 2023 · 5 comments
Closed

multipart/form-data - value must be an object #1169

Ol1BoT opened this issue Aug 2, 2023 · 5 comments

Comments

@Ol1BoT
Copy link

Ol1BoT commented Aug 2, 2023

version: v1.13.0

When I POST a multipart/form I get the following:

code=400, message=request body has an error: doesn't match schema: value must be an object, internal=request body has an error: doesn't match schema: value must be an object

I've clipped off the rest for brevity.

The yaml looks as follows:

  /api/v1/upload/{id}:
    post:
      operationId: FileUpload
      x-requires-permission: user:write
      parameters:
        in: path
        name: id
        schema:
          type: string
        required: true
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary

and the cURL command i'm using is

curl --request POST \
  --url https://site.com/api/v1/upload/<id> \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: multipart/form-data' \
  --form file=@/uploads/to_upload.zip

I seem to be following the openapi spec to a T, I also added in the following:

openapi3filter.RegisterBodyDecoder("application/zip", openapi3filter.FileBodyDecoder)
openapi3filter.RegisterBodyDecoder("multipart/form-data", openapi3filter.FileBodyDecoder)

I don't think the application/zip is necessary but I've included it anyway.

I've been using #514 as a reference but I've seem to run out of things to try.

@Ol1BoT Ol1BoT changed the title multipart/form - value must be an object multipart/form-data - value must be an object Aug 2, 2023
@Ol1BoT
Copy link
Author

Ol1BoT commented Aug 2, 2023

removing the middleware.OapiRequestValidator(swaggerSpec) "fixes" the issue.

Is it something I'm doing incorrectly or should I investigate why the middleware isn't considering this a valid object?

@Ol1BoT
Copy link
Author

Ol1BoT commented Aug 2, 2023

issue with kin-openapi, closing.

@lukasbash
Copy link

I am facing the same problem. Can you elaborate a bit how kin-openapi is connected to this issue? Also, skipping the validation is not really an option for me.

Is there something I can change without skipping the validator?

@Ol1BoT
Copy link
Author

Ol1BoT commented Feb 20, 2024

@lukasbash
Delete openapi3filter.RegisterBodyDecoder("multipart/form-data", openapi3filter.FileBodyDecoder)

@lukasbash
Copy link

lukasbash commented Feb 20, 2024

@Ol1BoT
I already removed this line. Without the following code

			Skipper: func(ctx echo.Context) bool {
				cts := ctx.Request().Header["Content-Type"]

				return lo.SomeBy(cts, func(ct string) bool {
					return strings.Contains(ct, "multipart/form-data")
				})
			},

I get an error request body has an error: failed to decode request body: path file: unsupported content type \"image/png\"

This is my API requestBody content:

          multipart/form-data:
            schema:
              type: object
              required:
                - "file"
              properties:
                file:
                  type: string
                  format: binary
            encoding:
              file:
                contentType: image/png, image/jpeg

EDIT: Never mind as I forgot to add the image body decoders. Thank you so much for the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants