Swagger generator doesn't recognize controller

一曲冷凌霜 提交于 2019-12-10 22:49:15

问题


I have this yaml file:

---
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"

When I run swagger-codegen-cli, generates /api/Default.js and /api/DefaultService.js , but no /api/weatherController.js.

I've tried also with this:

---
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"

And I run the generator with this command:

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

How can I do this?


回答1:


I think that's a bug, it would be great if you could file that on the swagger-codegen project. But as a work around, consider adding a tag:

/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"


来源:https://stackoverflow.com/questions/38295951/swagger-generator-doesnt-recognize-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!