Nullpo Nullpo - 4 months ago 40
Node.js Question

Swagger generator doesn't recognize controller

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?

Answer

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"