vinejs / vine

VineJS is a form data validation library for Node.js
https://vinejs.dev
MIT License
1.1k stars 21 forks source link

Vine Enum with nullable #70

Open kevinmelo opened 3 months ago

kevinmelo commented 3 months ago

Package version

latest

Describe the bug

When i validate using VineJs and one of the keys is a enum but can be null it's give me de following error:

TypeError: Cannot convert undefined or null to object at Function.values (<anonymous>) at _VineNativeEnum

with the following json:

 {
    "object": "my_object",
    "entry": [
        {
            "id": "0",
            "time": 1723073445,
            "changes": [
                {
                    "field": "any_field",
                    "value": {
                        "event": "APPROVED",
                        "message_template_id": 12345678,
                        "message_template_name": "my_message_template",
                        "message_template_language": "pt-BR",
                        "reason": null
                    }
                }
            ]
        }
    ]
}

The Complete vine schema:

export default vine.compile(
    vine.object({
        object: vine.string(),
        entry: vine.array(
            vine.object({
                id: vine.string(),
                time: vine.number(),
                changes: vine.array(
                    vine.object({
                        field: vine.string(),
                        value: vine.object({
                            event: vine.enum(OTHER_ENUM),
                            message_template_id: vine.number(),
                            message_template_name: vine.string(),
                            message_template_language: vine.string(),
                            reason: vine.enum(MY_ENUM).nullable(),
                        }),
                    })
                ),
            })
        ),
    })
)

Where the erro occurs reason: vine.enum(MY_ENUM).nullable(),

Reproduction repo

No response

thetutlage commented 3 months ago

Can you please share the complete Vine schema

kevinmelo commented 3 months ago

Can you please share the complete Vine schema

Sure, i update the first comment with the Vine Schema