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
Add specification property field's values restrictions based on validator setting #3329
Add specification property field's values restrictions based on validator setting #3329
Conversation
d912241
to
75d8123
Compare
src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaRegexRestriction.php
Outdated
Show resolved
Hide resolved
src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php
Outdated
Show resolved
Hide resolved
} | ||
} | ||
} | ||
|
||
return $propertyMetadata->withIri($iri)->withRequired($required ?? false); | ||
$propertyMetadata = $propertyMetadata->withIri($iri)->withRequired($required ?? false); |
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.
We don't break the above loop anymore, and it looks like we can have multiple constraints, hence different iris? I'm not sure that this case is handled / implemented correctly.
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.
@soyuka Like in previous implementation we continue to set IRI
and required
only if it was not set before.
$schema = []; | ||
} | ||
|
||
$schema += array_merge(...$restrictions); |
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.
Do we really need this spread operator / array_merge?
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.
Yes we must merge all restrictions into one schema
src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php
Outdated
Show resolved
Hide resolved
tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
tests/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php
Outdated
Show resolved
Hide resolved
src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaLengthRestriction.php
Outdated
Show resolved
Hide resolved
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.
Great addition! Thanks for working on this.
src/Bridge/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaFormat.php
Outdated
Show resolved
Hide resolved
@@ -67,11 +68,19 @@ final class ValidatorPropertyMetadataFactory implements PropertyMetadataFactoryI | |||
|
|||
private $decorated; | |||
private $validatorMetadataFactory; | |||
/** | |||
* @var iterable<PropertySchemaRestrictionMetadataInterface> |
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.
Can you move it to the constructor please?
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.
fixed
public function __construct(ValidatorMetadataFactoryInterface $validatorMetadataFactory, PropertyMetadataFactoryInterface $decorated) | ||
{ | ||
public function __construct( | ||
ValidatorMetadataFactoryInterface $validatorMetadataFactory, |
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.
We put every parameters on the same line (same everywhere).
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.
fixed
src/Bridge/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactory.php
Outdated
Show resolved
Hide resolved
public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null, SubresourceMetadata $subresource = null, bool $initializable = null, $default = null, $example = null) | ||
{ | ||
/** | ||
* @var array |
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.
to remove (and should be array|null
)
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.
fixed
/** | ||
* @param PropertySchemaRestrictionMetadataInterface[] $restrictionsMetadata | ||
*/ | ||
public function __construct(ValidatorMetadataFactoryInterface $validatorMetadataFactory, PropertyMetadataFactoryInterface $decorated, iterable $restrictionsMetadata) |
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.
Can we default iterable $restrictionsMetadata to an array? I fear it may break some implementations if we leave this as-is.
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.
@soyuka I've added default value
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.
nice thanks, may you rebase/sqash? I'd like to merge this.
0a7461a
to
e9bdc58
Compare
@soyuka Thanks, done. |
e9bdc58
to
38d6955
Compare
Thanks @penja! |
case Type::BUILTIN_TYPE_INT: | ||
case Type::BUILTIN_TYPE_FLOAT: | ||
if (isset($constraint->min)) { | ||
$restriction['minimum'] = (int) $constraint->min; | ||
} | ||
|
||
if (isset($constraint->max)) { | ||
$restriction['maximum'] = (int) $constraint->max; | ||
} |
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 part looks wrong. Length
is a string constraint. There seems to be confusion with Range
, implemented in #4158
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.
That's right. Could you provide a PR to fix it?
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.
PR: #4177
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.
PS: thanks @penja for implementing this feature!
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.
@guilliamxavier thanks for fix
Generate specification property restrictions based on Symfony’s built-in validator.