node.js - Swagger 生成器无法识别 Controller

标签 node.js swagger swagger-2.0

我有这个 yaml 文件:

---
swagger: "2.0"
info:
  version: 0.1.0
  title: "My API"
host: localhost:3000
basePath: /api
schemes:
  - http
paths:
    /weather:
      get:
        x-swagger-router-controller: "weatherController"
        description: "Returns current weather in the specified city to the caller"
        operationId: getWeather
        parameters:
          - name: city
            in: query
            description: "The city you want weather for in the form city,state,country"
            required: true
            type: "string"

当我运行 swagger-codegen-cli 时,生成/api/Default.js 和/api/DefaultService.js ,但没有/api/weatherController.js 。

我也尝试过这个:

---
swagger: "2.0"
info:
  version: 0.1.0
  title: "My API"
host: localhost:3000
basePath: /api
schemes:
  - http
paths:
    /weather:
      x-swagger-router-controller: "weatherController"
      get:
        description: "Returns current weather in the specified city to the caller"
        operationId: getWeather
        parameters:
          - name: city
            in: query
            description: "The city you want weather for in the form city,state,country"
            required: true
            type: "string"

我使用以下命令运行生成器:

java -jar swagger-codegen-cli.jar generate -l nodejs-server -o output -i api.yaml

我该怎么做?

最佳答案

我认为这是一个错误,如果您可以将其归档到 swagger-codegen 项目中,那就太好了。但作为解决方法,请考虑添加标签:

/weather:
  x-swagger-router-controller: "weatherController"
  get:
    tags:
    - weatherController
    description: "Returns current weather in the specified city to the caller"
    operationId: getWeather
    parameters:
      - name: city
        in: query
        description: "The city you want weather for in the form city,state,country"
        required: true
        type: "string"

关于node.js - Swagger 生成器无法识别 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38295951/

相关文章:

node.js - 如何删除 sails js 默认日志消息

rest - 内部错误 (500) 是否应该成为 Swagger API 文档的一部分?

c# - ASP.NET Core - Swashbuckle 未创建 swagger.json 文件

javascript - 有没有办法在 swagger-ui 3.* 中只呈现特定的 api 端点?

mysql - 如何将sql server连接到app.js文件?

node.js - 批量写入 - 类型错误 : Cannot create property '$set' on number '0' at applyTimestampsToUpdate - mongoose or mongodb

node.js - Node express ejs 错误 : Failed to lookup view "error" in views directory

python - JWT 不接受 Bearer 授权

swagger - Swagger 2.0在哪里声明基本身份验证架构

asp.net-web-api - 我怎样才能告诉Swashbuckle人体必需的成分?