Open besmillahibrahimi opened 1 year ago
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?
For your case. You have as the following.
app.post( '/uploads', ({ body }) => body, { body: t.Object({ foo: t.File({ type: ['image'] }), }), } )
the issue with t.Files
is that swagger-ui / scalar can't handle these default
and elysiaMeta
properties within the generated json:
{
"openapi": "3.0.3",
"info": {
"title": "Elysia Documentation",
"description": "Development documentation",
"version": "0.0.0"
},
"paths": {
"/": {
"post": {
"parameters": [],
"operationId": "postIndex",
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"files": {
-- "elysiaMeta": "Files",
-- "default": "Files",
"type": "array",
"items": {
"default": "Files",
"type": "string",
"format": "binary"
}
}
},
"required": [
"files"
]
}
}
}
},
"responses": {
"200": {}
}
}
}
},
"components": {
"schemas": {}
}
}
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!