arb / celebrate

A joi validation middleware for Express.
MIT License
1.33k stars 66 forks source link

Mode FULL doesn't seem to be working. #231

Closed JdSeus closed 2 years ago

JdSeus commented 2 years ago

Hello everyone, I'm trying to use Celebrate on mode FULL but it doesn't seem to be working.

Here is my Schema:

image

(I have tried before this way, but got the same results image )

This is my my require at ClientsController (where exports.postClientValidation is): image

This is how i'm using Celebrate:

image

ClientsController.postClient is irrelevant in this case, since i'm testing the validation of Celebrate, which is encapsulated in ClientsController.postClientValidation.

This is the result on Postman, when 3 fields are deselected:

image

If I understood it correctly, it should be something like that on mode full:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Validation failed",
    "validation": {
        "body": {
            "source": "body",
            "keys": [
                "nome", 
                "endereco", 
                "cep"
            ],
            "message": "\"nome\" is required. \"endereco\" is required. \"cep\" is required."
        }
    }
}

I'm not sure about the validation message though.

Anyway, is it something I did wrong? Or mode full is not working?

Thanks in advance.

JdSeus commented 2 years ago

Sorry. It seems to be duplicated of https://github.com/arb/celebrate/issues/228.

I recommend put in the documentation that joiOptions should be something like that {warnings: true, abortEarly: false} to full mode work properly.

image

image

Anyway, thanks.

arb commented 2 years ago

Any PR that improves the documentation are always welcome 😄