{"record":{"id":"c29068c79a08b447","repo":"symfony/routing","slug":"the-routing-file-s-must-not-specify-both-the-resource-key","errorCode":null,"errorMessage":"The routing file \"%s\" must not specify both the \"resource\" key and the \"path\" key for \"%s\". Choose between an import and a route definition.","messagePattern":"The routing file \"(.+?)\" must not specify both the \"resource\" key and the \"path\" key for \"(.+?)\"\\. Choose between an import and a route definition\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/ContentLoaderTrait.php","lineNumber":220,"sourceCode":"    /**\n     * @throws \\InvalidArgumentException If one of the provided config keys is not supported,\n     *                                   something is missing or the combination is nonsense\n     */\n    private function validate(mixed $config, string $name, string $path): void\n    {\n        if (!\\is_array($config)) {\n            throw new \\InvalidArgumentException(\\sprintf('The definition of \"%s\" in \"%s\" must be an array.', $name, $path));\n        }\n        if (isset($config['alias'])) {\n            $this->validateAlias($config, $name, $path);\n\n            return;\n        }\n        if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" contains unsupported keys for \"%s\": \"%s\". Expected one of: \"%s\".', $path, $name, implode('\", \"', $extraKeys), implode('\", \"', self::AVAILABLE_KEYS)));\n        }\n        if (isset($config['resource']) && isset($config['path'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" must not specify both the \"resource\" key and the \"path\" key for \"%s\". Choose between an import and a route definition.', $path, $name));\n        }\n        if (!isset($config['resource']) && isset($config['type'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The \"type\" key for the route definition \"%s\" in \"%s\" is unsupported. It is only available for imports in combination with the \"resource\" key.', $name, $path));\n        }\n        if (!isset($config['resource']) && !isset($config['path'])) {\n            throw new \\InvalidArgumentException(\\sprintf('You must define a \"path\" for the route \"%s\" in file \"%s\".', $name, $path));\n        }\n        if (isset($config['controller']) && isset($config['defaults']['_controller'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" must not specify both the \"controller\" key and the defaults key \"_controller\" for \"%s\".', $path, $name));\n        }\n        if (isset($config['stateless']) && isset($config['defaults']['_stateless'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" must not specify both the \"stateless\" key and the defaults key \"_stateless\" for \"%s\".', $path, $name));\n        }\n        if (isset($config['firewall']) && isset($config['defaults']['_firewall'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" must not specify both the \"firewall\" key and the defaults key \"_firewall\" for \"%s\".', $path, $name));\n        }\n    }\n","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/ContentLoaderTrait.php#L202-L238","documentation":"A single routing definition may be either an import (resource) or a concrete route (path), but not both. validate() throws an InvalidArgumentException when a definition specifies both 'resource' and 'path' keys, since the two are mutually exclusive.","triggerScenarios":"A YAML/PHP definition like `home: { resource: routes/, path: / }` — combining an import with a route path, often after merging config fragments or copy-paste edits.","commonSituations":"Merging route config arrays where defaults and imports got combined; editing an import into a route (or vice versa) without removing the old key; config merge tools concatenating both branches.","solutions":["Keep only 'resource' if the entry should import another file; delete the 'path' key.","Keep only 'path' (plus controller etc.) if it is a concrete route; delete the 'resource' key.","Split into two separate named definitions if you need both an import and a route."],"exampleFix":"# before\nhome:\n    resource: routes/home.yaml\n    path: /\n# after\nhome:\n    resource: routes/home.yaml","handlingStrategy":"validation","validationCode":"if (isset($config['resource']) && isset($config['path'])) { throw new \\InvalidArgumentException('resource and path are mutually exclusive'); }","typeGuard":null,"tryCatchPattern":"try { $loader->load($file); } catch (\\InvalidArgumentException $e) { /* split the definition or drop one key */ }","preventionTips":["Treat 'resource' and 'path' as either/or per definition.","Check merged config output for combined keys.","Split imports and routes into separate named entries."],"tags":["routing","config-validation","mutually-exclusive","symfony"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}