路由参数无法从 ExpressJs api 中的 Swagger UI 正确填充

问题描述 投票:0回答:1

我正在将 Swagger 实现到 ExpressJs API 应用程序中。在控制器文件中,我们使用嵌套文件夹和“const router = require('express').Router({ mergeParams: true });”从父文件夹继承路径变量。当我运行 swagger 实现时,任何比父文件夹更深的内容都不会动态放入 swagger UI 提供的路由变量中。示例:我将在 swagger ui 中的文本框中输入变量“mineID”和“incidentId”,然后这就是 swagger ui 中显示的确切的curl 请求,您可以在其中看到第二个路由参数尚未填充,因为它应该来自用户界面:

curl -X 'GET' \
  'http://localhost:4900/v2/mines/5555/incidents/{incidentId}/actions' \
   ***** bearer token etc here

在我的 swagger 实现中,我在单独的文件中使用 jsdocs,但与控制器代码位于同一文件夹中。 我的 JsDocs 定义使用相同的参数名称,如下所示:

/**
 * @swagger
 * /v2/mines/{mineId}/incidents/{incidentId}/actions:
 *   get:
 *     summary: Get all actions associated with a specific incident
 *     description: |
 *       Retrieves all actions related to a specified incident, including details about each action's outcomes.
 *
 *       **Permissions Required**
 *       - `IncidentPermissions.VIEW_ACTIONS`
 *     tags:
 *       - Mines/Incidents/Actions
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: mineId
 *         required: true
 *         schema:
 *           type: string
 *         description: The unique identifier of the mine.
 *       - in: path
 *         name: incidentId
 *         required: true
 *         schema:
 *           type: string
 *         description: The unique identifier of the incident.

这是我的 ExpressJs 控制器代码,路径为 xxx/v2/mines/:mineId/incidents/:incidentId/actions。这条路线按照邮递员中的预期运行并且正在生产中,所以我相信这不是控制器的问题:

router.get('/', async function (req, res, next) {
    // @ts-ignore mineId is defined in *** file and brought in with "mergeParams"
    const mineId = req.params.mineId;
    // @ts-ignore incidentId is defined in *** file and brought in with "mergeParams"
    const incidentId = req.params.incidentId;

    // rest of controller code

});

如何正确填充这些变量?它在应用程序的其他地方工作,我只需要 swagger 实现的解决方案,API 代码经过测试并且可以自行正常工作。我进行了大量搜索,但找不到答案。

express swagger swagger-ui jsdoc swagger-jsdocs
1个回答
0
投票

Swagger UI v. 5.17.7 中的路径参数存在错误。它已在 v.5.17.8 中修复。

© www.soinside.com 2019 - 2024. All rights reserved.