-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DependencyInjection][Routing] Add JSON schema for validating and autocompleting YAML config files #61282
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
base: 7.4
Are you sure you want to change the base?
Conversation
…ocompleting YAML config files
This comment was marked as resolved.
This comment was marked as 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.
The version number was never updated for the xsd file name. I think a shorter file name would be better as it needs to be in all the Yaml files that use it.
# $schema: ../../vendor/symfony/dependency-injection/Loader/schema/dic/services/services-1.0.schema.json
Maybe:
# $schema: ../../vendor/symfony/dependency-injection/Loader/schema/services.schema.json
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 could also host those files on symfony.com so that the link could always be absolute?
Little bit off topic, but what do you think about a JsonSchema component? we could also reuse this in symfony/ai |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
not mine to write, that typically the kind of stuff I'd rather outsource to another lib |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as 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.
I've noticed a few issues while testing.
"type": "object", | ||
"properties": { | ||
"class": { "type": "string" }, | ||
"arguments": { "type": "array", "items": { "$ref": "#/$defs/parameterValue" } }, |
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.
When using named arguments this can be an object as well:
My\Class:
arguments:
$one: '@service'
$two: { }
"bind": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^\\$[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$": { "$ref": "#/$defs/parameterValue" } |
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.
bind
can also have a class name:
bind:
My\Class $myClass: '@foo'
}, | ||
"decorates": { "type": "string" }, | ||
"decoration_inner_name": { "type": "string" }, | ||
"decoration_priority": { "type": "integer" } |
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.
lazy
and synthetic
are missing:
My\Class:
lazy: true
My\Class2:
synthetic: true
Also, resource
and exclude
, but maybe that should be under a different pattern that ends with \
:
My\Ns\:
resource: '../src/'
exclude:
- '../src/Foo/'
"calls": { | ||
"type": "array", | ||
"items": { | ||
"type": "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.
calls
also accepts the following syntax:
My\Class:
calls:
- setLogger: ['@logger']
"title": "Symfony Parameters and Services Configuration", | ||
"description": "Defines application parameters and services, including environment-specific conditionals.", | ||
"type": "object", | ||
"properties": { |
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.
You can also specify imports here:
imports:
- { resource: one.yaml }
- { resource: two.yaml }
Related to #59620
This provides autocompletion/validation on IDEs that support JSON schema for YAML files, such as phpStorm.
These files have been generated by Gemini.
I see them as a starting point for the community, contributions welcomed for improving the files if needed.
For the record, I first tried converting our XSD files into JSON schema, but this doesn't work since the config layout in XML files is not the same as in YAML ones.