Skip to content

[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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Member

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

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jul 31, 2025

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?

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": {
"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" } },
"tags": {
"type": "array",
"items": {
"oneOf": [
{ "type": "string" },
{
"type": "object",
"properties": { "name": { "type": "string" } },
"required": ["name"],
"additionalProperties": true
}
]
}
},
"calls": {
"type": "array",
"items": {
"type": "array",
"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" }
},
"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" }
},
"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
}
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy