-
Notifications
You must be signed in to change notification settings - Fork 354
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
fix bug when applying defaults #405
Conversation
6dce921
to
0771bff
Compare
Nice catch! Appreciate you finding / fixing this :-). It's 2:15am here, but your bug report has made me think - if The comment on test #21 needs fixing, it says the same thing twice. I'll review this properly in the morning when I'm not half asleep ;-). |
yes we could :)
fixed
👍 |
@@ -149,6 +149,16 @@ public function getValidTests() | |||
'{"items":[{"default":null}]}', | |||
'[null]' | |||
), | |||
array(// #21 items might be an array of schema (instead of an array of schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs clarifying - it says the same thing twice.
@@ -149,6 +149,16 @@ public function getValidTests() | |||
'{"items":[{"default":null}]}', | |||
'[null]' | |||
), | |||
array(// #21 items might be an array of schema (instead of an array of schema) | |||
'[{}]', | |||
'{"items":{"properties":{"propertyOne":{"default":"valueOne"}},"required":[]}}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of required
in this test?
), | ||
array(// #22 if items is not an array, it does not create new item | ||
'[]', | ||
'{"items":{"properties":{"propertyOne":{"default":"valueOne"}},"required":[]}}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of required
in this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they were not, it's just how I found out about this bug and I didn't realized I could remove it from the tests
Thanks for fixing this bug :-).
Are you intending to do the work on |
0771bff
to
ea6bf9f
Compare
I've added support for minItems, tell me if you think of something missing (I'll squash everything when it's ready to merge) |
03a09cd
to
b854caa
Compare
if (LooseTypeCheck::isArray($schema->items)) { | ||
$items = $schema->items; | ||
} elseif (isset($schema->minItems) && count($value) < $schema->minItems) { | ||
$items = array_fill(count($value), $schema->minItems - 1, $schema->items); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the magic number? Shouldn't this be less count($value)
, rather than less 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely! I thought the second argument of array_fill was $end_index
but it's $num
…
$items = array(); | ||
if (LooseTypeCheck::isArray($schema->items)) { | ||
$items = $schema->items; | ||
} elseif (isset($schema->minItems) && count($value) < $schema->minItems) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to check and handle the state of $schema->exclusiveMinimum
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I has no idea this existed, I'll add a test for exclusiveMinimum
should be ok if I understood |
Grrr.... I've sent you on a wild goose chase sorry, Eveything else looks fine; once the |
don’t worry, I read its definition too quickly too, it’s gone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks :-)
all items and add support for minItems when applying defaults
a631e70
to
eef0954
Compare
rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
…jsonrainbow#405) all items and add support for minItems when applying defaults
* Split $objectDefinition into $schema and $properties (#411) Object validation attempts to use a single variable to store both the object definition, and its properties. This causes validation to be incomplete where "properties" is not set, but "additionalProperties" is. This commit fixes both bugs in issue #353. * Issue-414: Allow The Option of T or space for Date time. (#415) * Testcase for minProperties with properties defined (#416) + Fix Test * Tweak phpdocumentor dependency to avoid install conflicts (#421) * [BUGFIX] Cast empty schema arrays to object (#409) * Cast root to object * Use function_exists to allow polyfill compatibility * Move array->object conversion to SchemaConstraint & SchemaStorage Fixes issue #408 * fix bug when applying defaults for array items when the schema is for (#405) all items and add support for minItems when applying defaults * [BUGFIX] Split "uri" format into "uri" & "uri-reference", fix meta-schema bug (#419) * Split "uri" format into "uri" and "uri-reference" * Correct format for id & $ref in draft-03/04 meta-schemas See json-schema-org/JSON-Schema-Test-Suite#177 (comment)
to reproduce:
according to the spec:
but here the code supposes it's an array of schemas and it fails when it's trying to use
[]
(the value ofrequired
) as a schema