小编Liz*_*lis的帖子

如何在使用 swagger-ui-express 和 swagger-jsdoc 时正确使用 swagger 文件中的 $ref

我开始使用 swagger 和swagger-ui-expressswagger-jsdoc来自动记录我现有的 API,它是用nodejs和 express编写的(就像这里描述的一样 -示例)。

当我尝试在我的注释上添加一个$ref现有的JSON 模式文件(它与我的所有 js 文件位于我的项目中的同一目录中)时遇到了一个问题。

我的目录看起来像这样

我尝试编写本地路径 ( ./schema.json) 和绝对路径,尝试使用#,使用了许多语法,但没有任何效果。

我的注释是这样的:

/**
 * @swagger
 * /testing:
 *    get:
 *      description: This should show the json schema
 *      responses:
 *          200:
 *              description: "successful operation"
 *              schema:
 *                 $ref: "./schema.json"
 */
Run Code Online (Sandbox Code Playgroud)

我希望 swagger ui 在我的请求部分向我显示 JSON 模式。我收到以下错误 -

Resolver error at paths./testing.get.responses.200.schema.$ref
Could not resolve reference: Tried to resolve a relative …
Run Code Online (Sandbox Code Playgroud)

json ref node.js express swagger

11
推荐指数
1
解决办法
7659
查看次数

标签 统计

express ×1

json ×1

node.js ×1

ref ×1

swagger ×1