tobyzerner / json-api-server

A JSON:API server implementation in PHP.
https://tobyzerner.github.io/json-api-server/
MIT License
63 stars 21 forks source link

`Number` throws type error when not defining a `minimum()`, `maximum()` or `multipleOf()` #78

Closed bertramakers closed 1 year ago

bertramakers commented 1 year ago

When you set up a Number field without calling minimum(), maximum() or multipleOf(), the validation of the Number field will throw a TypeError like for example:

Typed property Tobyz\JsonApiServer\Schema\Field\Number::$minimum must not be accessed before initialization

The validation only works by calling all three methods, so that the validation function does not access uninitialized properties.

The easiest fix to me looks to default the corresponding properties to null, like this:

    private ?float $minimum = null;
    private bool $exclusiveMinimum;
    private ?float $maximum = null;
    private bool $exclusiveMaximum;
    private ?float $multipleOf = null;