Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some boolean/array properties have wrong values #77

Closed
Neokil opened this issue Aug 26, 2020 · 2 comments
Closed

Some boolean/array properties have wrong values #77

Neokil opened this issue Aug 26, 2020 · 2 comments
Labels
bug Something isn't working needs investigation Work is needed to figure out the root cause of the problem.
Milestone

Comments

@Neokil
Copy link

Neokil commented Aug 26, 2020

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.

@cebe
Copy link
Owner

cebe commented Aug 30, 2020

Good questions! The code in SpecBaseObject is quite generic and not related to Schema definitions directly.
The idea was that if we know the type of a property to return a value that fits in that type. That means empty array for array type and false for a boolean that is not explicitily set. There are some values that have a default value of true, e.g.

'additionalProperties' => true,

which corresponds to the spec:

http://spec.openapis.org/oas/v3.0.3#properties
additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. Consistent with JSON Schema, additionalProperties defaults to true.

For the cases you name, we need to check if they need to be adjusted.

@cebe cebe added bug Something isn't working needs investigation Work is needed to figure out the root cause of the problem. labels Aug 30, 2020
@cebe cebe added this to the 1.4.3 milestone Aug 30, 2020
@cebe cebe modified the milestones: 1.4.3, 1.6.0 Dec 23, 2020
@cebe cebe closed this as completed in 39b7cac Feb 9, 2022
@cebe
Copy link
Owner

cebe commented Feb 9, 2022

fixed. thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation Work is needed to figure out the root cause of the problem.
Projects
None yet
Development

No branches or pull requests

2 participants