Description:
I'm using the with_params validation system extensively, but I'm having trouble declaring a file_upload field as optional.
Lapis provides a types.file_upload type, and I expected to be able to combine it with types.empty to allow optional uploads. However, validation fails whenever no file is submitted in the form.
local lapis = require "lapis"
local capture_errors_json = require("lapis.application").capture_errors_json
local with_params = require("lapis.validate").with_params
local app = lapis.Application()
app:post("/send_file", capture_errors_json(with_params({
{"file", types.empty + types.file_upload}
}, function(self, params)
print("ok")
end)))
return app
In this case, validation does not pass if the file field is not present or empty.
Expected behavior:
The validation should pass when:
- No file is uploaded (empty field), OR
- A valid file upload is provided
Actual behavior:
Validation fails when the file field is empty or not included in the request.
Questions:
What is the correct way to declare an optional file_upload field using with_params?
Is there a recommended pattern or workaround for this use case?
Additional context:
Reference to file_upload type implementation:
|
file_upload = types.partial({ |
|
filename: types.string * -empty |
|
content: -types.literal("") |
|
})\describe "file upload" |
Thanks in advance!
Description:
I'm using the
with_paramsvalidation system extensively, but I'm having trouble declaring afile_uploadfield as optional.Lapis provides a
types.file_uploadtype, and I expected to be able to combine it withtypes.emptyto allow optional uploads. However, validation fails whenever no file is submitted in the form.In this case, validation does not pass if the
filefield is not present or empty.Expected behavior:
The validation should pass when:
Actual behavior:
Validation fails when the
filefield is empty or not included in the request.Questions:
What is the correct way to declare an optional file_upload field using with_params?
Is there a recommended pattern or workaround for this use case?
Additional context:
Reference to
file_uploadtype implementation:lapis/lapis/validate/types.moon
Lines 386 to 389 in ff773e8
Thanks in advance!