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

Swagger UI doesn't render t.Files() in body validation. #67

Open
besmillahibrahimi opened this issue Nov 9, 2023 · 2 comments
Open

Comments

@besmillahibrahimi
Copy link

Hello there,
I hope you are well.

I have a RESTful API written in Bun using Elysia. And I integrated @elysia-swagger. In one of my endpoints where I upload multiple files of the same fieldname and validate the body like below.

app.post("/", ({body}) => files, { body: { files: t.Files() } })

When I select application/form-data, while trying to upload files from Swagger UI, the exception is thrown. The error message is 😱 Could not render Parameters, see the console.

Error in console is
SyntaxError: Unexpected token 'F', "Files" is not valid JSON

Thanks!

@pratamatama
Copy link

Hi, I have the same issue here as well.
Using multipart/form-data request.

It is just a single file with t.File validation.

app.post(
    '/uploads',
    ({ body }) => body,
    {
        body: t.Object({
            digitalSignature: t.File({ type: ['image'] }),
        }),
    }
)

On me, it fails to validate and throw this error.

Invalid body, 'digitalSignature': Expected kind 'File'

Expected {
  "digitalSignature": "File"
}

Found: {
  "digitalSignature": {}
}

Can anyone provide solution for this?

@besmillahibrahimi
Copy link
Author

For your case. You have as the following.

app.post( '/uploads', ({ body }) => body, { body: t.Object({ foo: t.File({ type: ['image'] }), }), } )

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