{"record":{"id":"2dba037b3a6730e8","repo":"YMFE/yapi","slug":"plugin-route-config-error","errorCode":null,"errorMessage":"Plugin Route config Error","messagePattern":"Plugin Route config Error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/router.js","lineNumber":588,"sourceCode":"    },\n    {\n      action: 'runAutoTest',\n      path: 'run_auto_test',\n      method: 'get'\n    },\n    {\n      action: 'importData',\n      path: 'import_data',\n      method: 'post'\n    }\n  ]\n};\n\nlet pluginsRouterPath = [];\n\nfunction addPluginRouter(config) {\n  if (!config.path || !config.controller || !config.action) {\n    throw new Error('Plugin Route config Error');\n  }\n  let method = config.method || 'GET';\n  // let routerPath = '/plugin/' + config.path;\n  // 支持 /api/open/plugin 前缀的 openApi\n  let routerPath = (config.prefix || '') + '/plugin/' + config.path;\n  if (pluginsRouterPath.indexOf(routerPath) > -1) {\n    throw new Error('Plugin Route path conflict, please try rename the path');\n  }\n  pluginsRouterPath.push(routerPath);\n  createAction(router, '/api', config.controller, config.action, routerPath, method, false);\n}\n\nyapi.emitHookSync('add_router', addPluginRouter);\n\nfor (let ctrl in routerConfig) {\n  let actions = routerConfig[ctrl];\n  actions.forEach(item => {\n    let routerController = INTERFACE_CONFIG[ctrl].controller;","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/server/router.js#L570-L606","documentation":"addPluginRouter validates each plugin route config: path, controller, and action are all required; if any is missing it throws 'Plugin Route config Error'. The plugin's emitted route definition is incomplete.","triggerScenarios":"A plugin's add_router hook emits a route config object missing one of: path, controller, or action — e.g. addPluginRouter({path: 'foo', method: 'GET'}) without controller/action.","commonSituations":"Plugin author forgot required fields in its route definitions; plugin version incompatible with current YApi route API; conditional route construction yielding undefined fields.","solutions":["Fix the plugin's route config to include path, controller, and action.","Update or reinstall the plugin to a version compatible with the current YApi.","Check the plugin's server.js where it calls yapi.emitHookSync('add_router', ...) with route configs."],"exampleFix":"// before\naddPluginRouter({ path: 'stats' });\n// after\naddPluginRouter({ path: 'stats', controller: 'statController', action: 'get' });","handlingStrategy":"validation","validationCode":"function validatePluginRoute(cfg) {\n  const missing = ['path', 'controller', 'action'].filter(k => !cfg[k]);\n  if (missing.length) throw new Error(`Plugin route missing: ${missing.join(', ')}`);\n}","typeGuard":"function isValidPluginRoute(cfg) {\n  return !!cfg && typeof cfg.path === 'string' && cfg.path.length > 0 &&\n    typeof cfg.controller === 'string' && typeof cfg.action === 'string';\n}","tryCatchPattern":"try {\n  yapi.emitHookSync('add_router', addPluginRouter);\n} catch (e) {\n  if (e.message === 'Plugin Route config Error') {\n    console.error('A plugin emitted an incomplete route config (path/controller/action required)');\n  } else { throw e; }\n}","preventionTips":["Always define path, controller, and action in plugin route configs.","Validate route configs in the plugin before emitting add_router.","Test plugins in dev before enabling in production config.json."],"tags":["plugin","routing","configuration"],"backgroundTag":"invalid-plugin-route-config","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}