Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Config] Generate JSON schema for config#62125

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

Open
GromNaN wants to merge8 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromGromNaN:dx-config-schema-v2

Conversation

@GromNaN
Copy link
Member

@GromNaNGromNaN commentedOct 21, 2025
edited
Loading

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#59603
LicenseMIT

Supersede#59620, but generate nested objects instead of flatten definitions with hash as id. This is easier to read.

This PR only take care of the generating a JSON schema from a config node.
I also wrote this script that can be put in a composer plugin or a standalone script to generate a unique schema file for all the environments.

<?phpuseSymfony\Component\Config\Builder\JsonSchemaGenerator;useSymfony\Component\DependencyInjection\ContainerBuilder;useSymfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;useSymfony\Component\HttpKernel\Bundle\BundleInterface;require_once__DIR__.'/vendor/autoload.php';$bundles =require__DIR__.'/config/bundles.php';$jsonschemaGenerator =newJsonSchemaGenerator();$container =newContainerBuilder();// The debug parameter can vary based on the environment$container->setParameter('kernel.debug',true);$schema = (object) ['$schema' =>'http://json-schema.org/draft-07/schema#','type' =>'object','additionalProperties' =>false,'properties' =>new \stdClass(),'$defs' =>new \stdClass(),];$allEnvs = ['dev','prod','test'];foreach ($allEnvsas$env) {$schema->properties->{'when@' .$env} = (object)['type' =>'object','properties' =>new \stdClass(),'additionalProperties' =>false,    ];}foreach ($bundlesas$class =>$envs) {$bundle =new$class();assert($bundleinstanceof BundleInterface);$extension =$bundle->getContainerExtension();if ($extensioninstanceof ConfigurationExtensionInterface) {$configuration =$extension->getConfiguration([],$container);if ($configuration) {$node =$configuration->getConfigTreeBuilder()->buildTree();$name =$node->getName();$ref = (object) ['$ref' =>'#/$defs/'.$name];$schema->{'$defs'}->{$name} =$jsonschemaGenerator->generate($node);if ($envs === ['all' =>true]) {$schema->properties->{$name} =$ref;$envs =$allEnvs;            }else {$envs =array_keys(array_filter($envs));            }foreach ($envsas$env) {$schema->properties->{'when@'.$env}->properties->{$name} =$ref;            }        }    }}file_put_contents(__DIR__.'/config/schema.json',json_encode($schema,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR));

ging-dev and Jean-Beru reacted with hooray emojiging-dev reacted with rocket emoji
Comment on lines +221 to +224
if ($_ENV['TEST_GENERATE_FIXTURES'] ?? false) {
file_put_contents(__DIR__ . '/../Fixtures/Configuration/ExampleConfiguration.schema.json', $jsonSchema);
$this->markTestIncomplete('TEST_GENERATE_FIXTURES is set');
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Same pattern proposed in#62121

@stof
Copy link
Member

I also wrote this script that can be put in a composer plugin or a standalone script to generate a unique schema file for all the environments.

if you expect such script to be a supported use case, theJsonSchemaGenerator should not be an internal class, as this script relies on using this class.

@GromNaNGromNaNforce-pushed thedx-config-schema-v2 branch 2 times, most recently from4239dc4 to93c3cbbCompareOctober 22, 2025 16:30

if ($node->isDeprecated()) {
$schema['deprecated'] = true;
$schema['deprecationMessage'] = $node->getDeprecationMessage($node);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

deprecationMessage is not a JSON Schema key. This info should move todescription.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

[DX][Config] Generate JSON schema for Yaml configuration

4 participants

@GromNaN@stof@carsonbot@valtzu

[8]ページ先頭

©2009-2025 Movatter.jp