Validation error : "Invalid type for [...]. Expected: string" on not required field

Hi,
I created a cloud function with the following validation object :

    {
        fields: {
            id: {
                required: false,
                type: String
            }
        }
    }

As you can see, the field is set as not required. However, when I call the cloud function with an empty parameters object, I get this error, implying that the value of the field cannot be undefined :

Validation failed. Invalid type for id. Expected: string

Am I doing something wrong ?

I figured that in order to bypass this problem I could just remove the โ€œtypeโ€ field when a value isnโ€™t required. Still, I think it should be possible to inforce the type of a field even tho it isnโ€™t required, imo.

Still, I think it should be possible to inforce the type of a field even tho it isnโ€™t required, imo.

I agree. What happens if you pass an empty id?

In this case, the value is validated (since โ€œโ€ is considered as a String), so I guess that could be a way to solve this issue, even though it would required sending a payload larger than necessary whenever a function is called.

Yep that makes sense. You can suggest this in https://roadmap.moralis.io.