【问题标题】:No operations defined in spec Node.js Express规范 Node.js Express 中未定义任何操作
【发布时间】:2019-12-04 09:38:57
【问题描述】:

招摇用户界面

我正在尝试解决这个问题,但不知何故我还是没能做到。 /swagger 端点似乎只读取了 swagger.json 文件的一部分。我配置了所有内容,但仍然没有弹出一个错误。即使我创建了一个测试模型,它也只是说“规范中没有定义操作”。谷歌搜索这是一场灾难,文章很少,而且完全不同。

在 app.js 中我添加了:

import swaggerUi from "swagger-ui-express";
import * as swaggerDoc from "./swagger.json";
app.use("/swagger", swaggerUi.serve, swaggerUi.setup(swaggerDoc));

在 swagger.json 中:

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Stefan Back-end Swagger",
    "description": "Test",
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "Cat": {
    "type": "object",
    "properties": {
      "genus": {
        "type": "string"
      }
    }
  }
}

【问题讨论】:

  • 如果我没记错的话,Cat 应该在 swagger 文件中的“定义”下,以便稍后在“路径”定义中引用。 swagger.io/docs/specification/2-0/basic-structure
  • @volcanic 我需要把路径放在哪里?是的,对于定义,这是我的错误。没什么,找到了,去试试。谢谢(:

标签: javascript node.js express swagger documentation


【解决方案1】:

你使用的是openapi-3,看components section

你的swagger.json 文件应该是这样的:

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Stefan Back-end Swagger",
    "description": "Test",
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "components": {
    "schema": {
      "Cat": {
        "type": "object",
        "properties": {
          "genus": {
            "type": "string"
          }
        }
      }
    }
  }
}

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2020-11-27
    • 2020-10-01
    • 2018-11-07
    • 2023-03-08
    • 2019-02-10
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    相关资源
    最近更新 更多