Swagger发生器无法识别控制器

时间:2016-07-10 19:55:21

标签: 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

我该怎么做?

1 个答案:

答案 0 :(得分:3)

我认为这是一个错误,如果您可以在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"