elements icon indicating copy to clipboard operation
elements copied to clipboard

Boolean values are not sent as boolean while send request

Open LvckyAPI opened this issue 1 year ago • 1 comments

Context

Related to: https://github.com/dedoc/scramble/issues/615

In Laravel I try to validate boolean:

    public function index(Request $request)
    {
        $request->validate([
            'page' => 'sometimes|integer|min:1',
            'all' => 'sometimes|boolean'
        ]);
    }

The generated docs have correctly seen it needs boolean. At the sample request I can choose True or False.

image

Current Behavior

Validator says:

422 Unprocessable Entity

{
  "message": "The all field must be true or false.",
  "errors": {
    "all": [
      "The all field must be true or false."
    ]
  }
}

Stoplight Elements sends "true" and "false" strings as booleans, and Laravel API throws an error.

Expected Behavior

It should pass validation rules

Possible Solution(s)

If a boolean is required, send a boolean

LvckyAPI avatar Nov 11 '24 10:11 LvckyAPI

ping! :) @SB-ChetanKorde

boolean

The field under validation must be able to be cast as a boolean. Accepted input are true, false, 1, 0, "1", and "0".

You may use the strict parameter to only consider the field valid if its value is true or false:

chrillep avatar Aug 19 '25 16:08 chrillep