YMFE/yapi · error

Plugin Route config Error

Error message

Plugin Route config Error

What it means

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.

Source

Thrown at server/router.js:588

    },
    {
      action: 'runAutoTest',
      path: 'run_auto_test',
      method: 'get'
    },
    {
      action: 'importData',
      path: 'import_data',
      method: 'post'
    }
  ]
};

let pluginsRouterPath = [];

function addPluginRouter(config) {
  if (!config.path || !config.controller || !config.action) {
    throw new Error('Plugin Route config Error');
  }
  let method = config.method || 'GET';
  // let routerPath = '/plugin/' + config.path;
  // 支持 /api/open/plugin 前缀的 openApi
  let routerPath = (config.prefix || '') + '/plugin/' + config.path;
  if (pluginsRouterPath.indexOf(routerPath) > -1) {
    throw new Error('Plugin Route path conflict, please try rename the path');
  }
  pluginsRouterPath.push(routerPath);
  createAction(router, '/api', config.controller, config.action, routerPath, method, false);
}

yapi.emitHookSync('add_router', addPluginRouter);

for (let ctrl in routerConfig) {
  let actions = routerConfig[ctrl];
  actions.forEach(item => {
    let routerController = INTERFACE_CONFIG[ctrl].controller;

View on GitHub (pinned to 59bade3a8a)

Solutions

  1. Fix the plugin's route config to include path, controller, and action.
  2. Update or reinstall the plugin to a version compatible with the current YApi.
  3. Check the plugin's server.js where it calls yapi.emitHookSync('add_router', ...) with route configs.

Example fix

// before
addPluginRouter({ path: 'stats' });
// after
addPluginRouter({ path: 'stats', controller: 'statController', action: 'get' });
Defensive patterns

Strategy: validation

Validate before calling

function validatePluginRoute(cfg) {
  const missing = ['path', 'controller', 'action'].filter(k => !cfg[k]);
  if (missing.length) throw new Error(`Plugin route missing: ${missing.join(', ')}`);
}

Type guard

function isValidPluginRoute(cfg) {
  return !!cfg && typeof cfg.path === 'string' && cfg.path.length > 0 &&
    typeof cfg.controller === 'string' && typeof cfg.action === 'string';
}

Try / catch

try {
  yapi.emitHookSync('add_router', addPluginRouter);
} catch (e) {
  if (e.message === 'Plugin Route config Error') {
    console.error('A plugin emitted an incomplete route config (path/controller/action required)');
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: Plugin author forgot required fields in its route definitions; plugin version incompatible with current YApi route API; conditional route construction yielding undefined fields.

Related errors


AI-assisted analysis of YMFE/yapi@59bade3a8a (2026-08-29). Data as JSON: /api/errors/2dba037b3a6730e8. Report an issue: GitHub.