Skip to content

Inherited properties are partially nullable #28

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

Closed
wol-soft opened this issue Jan 28, 2021 · 1 comment · Fixed by #35
Closed

Inherited properties are partially nullable #28

wol-soft opened this issue Jan 28, 2021 · 1 comment · Fixed by #35
Assignees
Labels
bug Something isn't working
Milestone

Comments

@wol-soft
Copy link
Owner

Describe the bug
When using compositions the properties of the compositions are transferred to the main object. Independently of the implicitNull setting and the required state of the properties which are transferred from a composition the function signatures for getters and the DocBlocks for the properties are nullable.

With implicitNull setters of required properties become also nullable (although the validation performs correct checks and it will consequently fail if null is provided). Should be solved via the function signature.

Schema

{
  "$id": "Person",
  "allOf": [
    {
      "type": "object",
      "properties": {
        "age": {
          "type": "integer",
          "description": "The age of the person",
          "example": 42
        }
      }
    },
    {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "The name of the person",
          "example": "Lawrence"
        }
      },
      "required": [
        "name"
      ]
    }
  ]
}

implicitNull disabled

generated interface

        /** @var int|null The age of the person */
        protected $age = NULL;
        /** @var string|null The name of the person */
        protected $name = NULL;

        public function getAge(): ?int
        public function setAge(int $age): self
        public function getName(): ?string
        public function setName(string $name): self

expected interface

        /** @var int|null The age of the person */
        protected $age = NULL;
        /** @var string The name of the person */
        protected $name;

        public function getAge(): ?int
        public function setAge(int $age): self
        public function getName(): string
        public function setName(string $name): self

implicitNull enabled

generated interface

        /** @var int|null The age of the person */
        protected $age = NULL;
        /** @var string|null The name of the person */
        protected $name = NULL;

        public function getAge(): ?int
        public function setAge(?int $age): self
        public function getName(): ?string
        public function setName(?string $name): self

expected interface

        /** @var int|null The age of the person */
        protected $age = NULL;
        /** @var string The name of the person */
        protected $name;

        public function getAge(): ?int
        public function setAge(?int $age): self
        public function getName(): string
        public function setName(string $name): self

Version:
all versions

@wol-soft wol-soft added the bug Something isn't working label Jan 28, 2021
@wol-soft
Copy link
Owner Author

This behaviour only applies to the allOf composition as for all other compositions it can't be ensured the property must be set. Consequently for all other compositions the properties are set to nullable on the main object.

If the internal state of the object gets invalid by changing a property to null an exception will be thrown as the validations are executed. (compare changes made by the CompositionValidationPostProcessor)

wol-soft added a commit that referenced this issue Feb 8, 2021
BC break: function signatures for allOf compositions don't accept null any longer if `implicitNull` is not enabled or the property is required
@wol-soft wol-soft self-assigned this Feb 8, 2021
@wol-soft wol-soft added this to the 0.20.0 milestone Feb 8, 2021
@wol-soft wol-soft linked a pull request Feb 8, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant