-
-
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?
[DependencyInjection][Routing] Add JSON schema for validating and autocompleting YAML config files #61282
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"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 commentThe 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 } |
||
"parameters": { | ||
"type": "object", | ||
"description": "Defines application-wide parameters.", | ||
"patternProperties": { | ||
"^.*$": { "$ref": "#/$defs/parameterValue" } | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"services": { | ||
"type": "object", | ||
"description": "Defines your application services.", | ||
"properties": { | ||
"_defaults": { | ||
"$ref": "#/$defs/serviceDefaults" | ||
}, | ||
"_instanceof": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^.+$": { "$ref": "#/$defs/serviceDefaults" } | ||
}, | ||
"additionalProperties": false | ||
} | ||
}, | ||
"patternProperties": { | ||
"^[a-zA-Z0-9_\\\\.]+$": { | ||
"oneOf": [ | ||
{ "$ref": "#/$defs/serviceDefinition" }, | ||
{ "type": "null" }, | ||
{ "type": "string" } | ||
] | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
}, | ||
"patternProperties": { | ||
"^when@.+$": { | ||
"$ref": "#", | ||
"description": "A container for parameters and services that are only loaded in a specific environment." | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"$defs": { | ||
"parameterValue": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ "type": "number" }, | ||
{ "type": "boolean" }, | ||
{ "type": "array" }, | ||
{ "type": "object" }, | ||
{ "type": "null" } | ||
] | ||
}, | ||
"serviceDefinition": { | ||
"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 commentThe 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: { } |
||
"tags": { | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"properties": { "name": { "type": "string" } }, | ||
"required": ["name"], | ||
"additionalProperties": true | ||
} | ||
] | ||
} | ||
}, | ||
"calls": { | ||
"type": "array", | ||
"items": { | ||
"type": "array", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My\Class:
calls:
- setLogger: ['@logger'] |
||
"minItems": 1, | ||
"items": [{ "type": "string" }], | ||
"additionalItems": { "$ref": "#/$defs/parameterValue" } | ||
} | ||
}, | ||
"factory": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "array", | ||
"items": [ { "type": "string" }, { "type": "string" } ], | ||
"minItems": 2, | ||
"maxItems": 2 | ||
} | ||
] | ||
}, | ||
"properties": { "type": "object" }, | ||
"configurator": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "array", | ||
"items": [ { "type": "string" }, { "type": "string" } ], | ||
"minItems": 2, | ||
"maxItems": 2 | ||
} | ||
] | ||
}, | ||
"public": { "type": "boolean" }, | ||
"shared": { "type": "boolean" }, | ||
"abstract": { "type": "boolean" }, | ||
"parent": { "type": "string" }, | ||
"alias": { "type": "string" }, | ||
"autowire": { "type": "boolean" }, | ||
"autoconfigure": { "type": "boolean" }, | ||
"deprecated": { | ||
"oneOf": [ | ||
{ "type": "boolean" }, | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"message": { "type": "string" } | ||
}, | ||
"required": ["message"] | ||
} | ||
] | ||
}, | ||
"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 commentThe reason will be displayed to describe this comment to others. Learn more.
My\Class:
lazy: true
My\Class2:
synthetic: true Also, My\Ns\:
resource: '../src/'
exclude:
- '../src/Foo/' |
||
}, | ||
"additionalProperties": false | ||
}, | ||
"serviceDefaults": { | ||
"type": "object", | ||
"properties": { | ||
"autowire": { "type": "boolean" }, | ||
"autoconfigure": { "type": "boolean" }, | ||
"public": { "type": "boolean" }, | ||
"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 commentThe reason will be displayed to describe this comment to others. Learn more.
bind:
My\Class $myClass: '@foo' |
||
}, | ||
"additionalProperties": false | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Symfony Routing Configuration", | ||
"description": "Defines the application's URL routes, including imports and environment-specific conditionals.", | ||
"type": "object", | ||
"patternProperties": { | ||
"^[a-zA-Z0-9_.-]+$": { | ||
"oneOf": [ | ||
{ "$ref": "#/$defs/routeDefinition" }, | ||
{ "$ref": "#/$defs/routeImport" } | ||
] | ||
}, | ||
"^when@.+$": { | ||
"$ref": "#", | ||
"description": "A container for routes that are only loaded in a specific environment (e.g., 'when@dev')." | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"$defs": { | ||
"routeDefinition": { | ||
"type": "object", | ||
"properties": { | ||
"path": { | ||
"type": "string", | ||
"description": "The URL path for this route, which can contain parameters like /{id}." | ||
}, | ||
"controller": { | ||
"type": "string", | ||
"description": "The controller that handles the request, e.g., 'App\\Controller\\BlogController::show'." | ||
}, | ||
"methods": { | ||
"description": "The HTTP method(s) this route matches.", | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ "type": "array", "items": { "type": "string" } } | ||
] | ||
}, | ||
"requirements": { | ||
"type": "object", | ||
"description": "Regular expression constraints for path parameters.", | ||
"patternProperties": { "^.+$": { "type": "string" } } | ||
}, | ||
"defaults": { "type": "object" }, | ||
"options": { "type": "object" }, | ||
"host": { "type": "string" }, | ||
"schemes": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ "type": "array", "items": { "type": "string" } } | ||
] | ||
}, | ||
"condition": { "type": "string" }, | ||
"priority": { "type": "integer" }, | ||
"locale": { "type": "string" }, | ||
"format": { "type": "string" }, | ||
"utf8": { "type": "boolean" } | ||
}, | ||
"required": ["path"], | ||
"additionalProperties": false | ||
}, | ||
"routeImport": { | ||
"type": "object", | ||
"properties": { | ||
"resource": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"path": { "type": "string" }, | ||
"namespace": { "type": "string" } | ||
}, | ||
"required": ["path"], | ||
"additionalProperties": false | ||
} | ||
], | ||
"description": "Path to the resource (as a string) or an object with a 'path' and 'namespace'." | ||
}, | ||
"type": { | ||
"type": "string", | ||
"description": "The type of the resource (e.g., 'attribute', 'annotation', 'yaml')." | ||
}, | ||
"prefix": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ "type": "object", "patternProperties": { "^.+$": { "type": "string" } } } | ||
], | ||
"description": "A URL prefix to apply to all routes from the imported resource." | ||
}, | ||
"name_prefix": { | ||
"type": "string", | ||
"description": "A name prefix to apply to all routes from the imported resource." | ||
}, | ||
"requirements": { "type": "object" }, | ||
"defaults": { "type": "object" }, | ||
"options": { "type": "object" }, | ||
"host": { "type": "string" }, | ||
"schemes": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ "type": "array", "items": { "type": "string" } } | ||
] | ||
}, | ||
"condition": { "type": "string" }, | ||
"priority": { "type": "integer" }, | ||
"locale": { "type": "string" }, | ||
"format": { "type": "string" }, | ||
"utf8": { "type": "boolean" } | ||
}, | ||
"required": ["resource"], | ||
"additionalProperties": 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.
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
Uh oh!
There was an error while loading. Please reload this page.
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?