Skip to content

[Validator] Add Yaml constraint for validating YAML content #53749

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
Jun 14, 2024

Conversation

symfonyaml
Copy link
Contributor

@symfonyaml symfonyaml commented Feb 3, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Ticket? no
License MIT

Purpose

Inspired by the Json constraint, I've added a new feature to the Validator component for validating YAML content with a dedicated constraint.

Real world use case: Having configuration settings stored in YAML format within a database. With this new feature, you can validate the integrity of these configurations, ensuring the YAML syntax is OK.

Options

I've added a flags option to this constraint, aligning with the Yaml parser flags.

Exemple

namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Yaml\Yaml;

class Configuration
{
    #[Assert\Yaml(flags: Yaml::PARSE_DATETIME)]
    private string $content;
}

Copy link
Contributor Author

@symfonyaml symfonyaml left a comment

Choose a reason for hiding this comment

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

Resolved :)

@xabbuh
Copy link
Member

xabbuh commented Feb 4, 2024

Can you please rebase your changes onto the latest 7.1 branch? The failures mostly look related to issue we resolved recently.

@symfonyaml
Copy link
Contributor Author

The following Psalm issue looks like false positive to me 🤔 :

YamlValidator.php:43:95:
UndefinedVariable: Cannot find referenced variable $prevErrorHandler

This bit of code is a copy of the LintCommand::validate() method.

@symfonyaml symfonyaml force-pushed the feature-validator-yaml-constraint branch from d549f65 to 594682c Compare March 4, 2024 11:52
@symfonyaml symfonyaml force-pushed the feature-validator-yaml-constraint branch from 594682c to 912607b Compare April 12, 2024 08:16
Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

with the suggested change

@symfonyaml symfonyaml force-pushed the feature-validator-yaml-constraint branch from 17c1c8d to 5b95cfd Compare April 19, 2024 17:45
@symfonyaml
Copy link
Contributor Author

symfonyaml commented Apr 19, 2024

@xabbuh All done in commit 5b95cfd , thanks

@OskarStark OskarStark modified the milestones: 7.1, next Apr 22, 2024
@xabbuh xabbuh added ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" and removed ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" labels Apr 23, 2024
@symfonyaml symfonyaml force-pushed the feature-validator-yaml-constraint branch from 2c88c44 to e26da28 Compare May 7, 2024 18:04
Comment on lines +44 to +46
if (\E_USER_DEPRECATED === $level) {
throw new ParseException($message, $this->getParser()->getRealCurrentLineNb() + 1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the purpose of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ro0NL Taken from the Yaml LintCommand.php

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Rebase needed.

@symfonyaml symfonyaml force-pushed the feature-validator-yaml-constraint branch from e26da28 to bcbeb64 Compare June 13, 2024 17:03
@OskarStark OskarStark changed the title [Validator] Add Yaml constraint for validating Yaml content [Validator] Add Yaml constraint for validating YAML content Jun 14, 2024
@fabpot fabpot force-pushed the feature-validator-yaml-constraint branch from 1e36e57 to 023d48c Compare June 14, 2024 08:17
@fabpot
Copy link
Member

fabpot commented Jun 14, 2024

Thank you @symfonyaml.

@fabpot fabpot merged commit e0ad00c into symfony:7.2 Jun 14, 2024
7 of 10 checks passed
@symfonyaml symfonyaml deleted the feature-validator-yaml-constraint branch October 21, 2024 14:44
@fabpot fabpot mentioned this pull request Oct 27, 2024
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.

8 participants