Skip to content

Adjust default value for Schema:: when no type is specified #132

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

Merged
merged 1 commit into from
Nov 22, 2021

Conversation

cebe
Copy link
Owner

@cebe cebe commented Oct 28, 2021

fixes #131

@cebe cebe added this to the 1.6.0 milestone Oct 28, 2021
// nullable is only relevant, when a type is specified
// return null as default when there is no type
// return false as default when there is a type
'nullable' => $this->hasProperty('type') ? false : null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At what point this is calculated? Is schema->type mutable? Is this possible?

        // nullable is undefined if no type is given
        $schema = Reader::readFromJson('{"oneOf": [{"type": "string"}, {"type": "integer"}]}', Schema::class);
        $this->assertNull($schema->type);
        $this->assertNull($schema->nullable);
        $schema->type = Type::STRING;
        $this->assertFalse($schema->nullable);

If it's not mutable - looks good

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is executed on demand, e.g. in case the property is accessed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, then I think we need to fix this as a testcase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine default value for nullable property in Schema
2 participants