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

Nested JSON objects dont seem to work along with file uploads (multipart from request) #954

Open
mikkelam opened this issue Dec 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mikkelam
Copy link

mikkelam commented Dec 20, 2024

What version of Elysia is running?

1.1.26

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Having an endpoint that allows nested JSON structure doesn't seem to work. In this example i create an endpoint and use it with eden. Im not quite sure if it's eden that has the issue or Elysia. Please direct the issue accordingly.

test.ts:

import { Elysia, t } from "elysia";
import { treaty } from "@elysiajs/eden";

const app = new Elysia().post(
  "/image",
  ({ body: { image, nested } }) => nested,
  {
    type: "multipart/form-data",
    body: t.Object({
      nested: t.Object({
        key: t.String(),
      }),
      image: t.File(),
    }),
  },
);
const eden = treaty(app);

try {
  const resp = await eden.image.post({
    nested: { key: "value" },
    image: Bun.file("./test.ts"),
  });
  console.log(JSON.stringify(resp, null, 2));
} catch (error: any) {
  console.log("Error:", error.value);
}

What is the expected behavior?

200 status code, properly validating the nested object

What do you see instead?

Output:

❯ bun test.ts
{
  "data": null,
  "error": {
    "status": 422,
    "value": {
      "type": "validation",
      "on": "body",
      "summary": "Expected object",
      "property": "/nested",
      "message": "Expected object",
      "expected": {
        "nested": {
          "key": ""
        },
        "image": "File"
      },
      "found": {
        "image": {},
        "nested": "[object Object]"
      },
      "errors": [
        {
          "summary": "Expected object",
          "type": 46,
          "schema": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string"
              }
            },
            "required": [
              "key"
            ]
          },
          "path": "/nested",
          "value": "[object Object]",
          "message": "Expected object"
        }
      ]
    }
  },
  "response": {},
  "status": 422,
  "headers": {
    "content-type": "application/json"
  }
}

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yep

@mikkelam mikkelam added the bug Something isn't working label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant