Skip to content

Some boolean/array properties have wrong values #77

@Neokil

Description

@Neokil

When you are defining a Parameter like this:

"properties": {
    "code": {
        "description": "The Code of the Exception",
        "type": "integer",
        "example": 0
    },
    //...
}

and you try to get settings on that "code"-Property that are not set you will get values instead of null or undefined.
For example trying to get the "exclusiveMinimum"-Property will return "false" instead of null/undefined. This causes other frameworks like "justinrainbow/json-schema" to be unable to handle this.
I found the code responsible for this behaviour in src/SpecBaseObject.php::__get (Line 341):

337    if (isset($this->attributes()[$name])) {
338        if (is_array($this->attributes()[$name])) {
339            return [];
340        } elseif ($this->attributes()[$name] === Type::BOOLEAN) {
341            return false;
342        }
343        return null;
344    }

Is there a reason why array and boolean are specially handled here? From my POV that is strange because when I am trying to get the value of a setting that is not set I would expect those to be undefined.
Best example is the "exclusiveMinimum"-Setting of the Integer-Type which will be set to false by this function if not set what will cause the schema to be invalid because there is no minimum defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds investigationWork is needed to figure out the root cause of the problem.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions