Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Validator] Add newSchema
validation constraint#58560
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
configClass
option check to Yaml constraint usingsymfony/config
.configClass
option check to Yaml constraint usingsymfony/config
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
0f3a7cf
to31aced8
CompareDoes this really belong in the |
I doubt that this is a common enough use case that justifies to add this feature to the Symfony core. |
IMO, now that there is a Yaml constraint, I think config validation will be common. It allow to validate your Yaml tree directly (e.g. in form submit, or API call) without more action but to create your Configuration class. That way, you ensure the Yaml can be validate soon in your process without to much code to do it. IMO, it can be good to also add this to Json constraint too. |
I have never see an application where the config for a bundle is managed by a user of the application. Can you explain with more details how your actual use case looks like please? |
WedgeSama commentedOct 15, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The case I see is not about bundle's configuration (and you are right, bundle's config must not be managed by your app interface). It is about configuration in general. In some app, you can find/manage config for other app or parts of the app itself, likeHome Assistant for example (just the principle). In the case of Home Assistant, Yaml is used to configure and customize users' dashboard, directly from the web interface, by each user. And the problem for this example is the lack of validation on submit. With this PR, problem solve. I know some app I worked on where this capability will have been good. |
@WedgeSama I would suggest you to create a custom constraint in your project for that case (or in a third-party bundle if you want to reuse it). I don't think this use case is common enough to justify adding it in the core. Btw, your proposal requires that the provided config class can be instantiated with no argument, which is not guaranteed at all by the interface. |
After a chat with@Neirda24 it may be more relevant to use encapsulation ofCollection constraint to do only validation. It will match more the logic of the Validator. It will do something similar to what I wanted to do, but without I'll update the PR. |
fcd9a0e
to5932e71
CompareconfigClass
option check to Yaml constraint usingsymfony/config
5932e71
to2b2851c
CompareSchema
validation constraint.This constraint is like an extension of `Json` and `Yaml` constraints. It checks if given value is valid for the given format, then, if you declare `constraints` option, it will try to apply those constraints to the deserialized data.
2b2851c
to9da3762
CompareIf I want to validate a JSON against an actual schema, I would create a new constraint using, for example,https://packagist.org/packages/justinrainbow/json-schema. I'm not sure I would like to rewrite it with constraints by hand. As far as I can tell, for the Yaml part, the PR only validates that the Yaml is valid, no schema is actually checked? Also, you're restoring an error handler in the validator but you didn't set one, what's the reason? |
Schema
validation constraint.Schema
validation constraintvaltzu commentedOct 23, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I recall having a similar need in the past, also related to config management via UI – so +1 for the idea from me. Instead of putting serializer logic into validator component, how about adding a And then in the framework config wire |
Perhaps it would be better if this was an optional |
Uh oh!
There was an error while loading.Please reload this page.
This constraint is like an extension of
Json
andYaml
constraints. It checks if given value is valid for the given format, then, if you declareconstraints
option, it will try to apply those constraints to the deserialized data.Usage examples: