【问题标题】:Cannot resolve the configured swagger-router handler: movie_get无法解析配置的 swagger-router 处理程序:movie_get
【发布时间】:2018-05-03 22:14:49
【问题描述】:

我将 Swagger 与 NodeJS 一起使用,当我测试一个示例时,我有 this error

这是我的 YAML:

swagger: "2.0"
info:
  version: "0.0.1"
  title: Hello World App
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths 
basePath: /
# 
schemes:
  # tip: remove http to make production-grade
  - http
  - https
# format of bodies a client can send (Content-Type)
consumes:
  - application/json
# format of the responses to the client (Accepts)
produces:
  - application/json
paths:
  /movie:
    # our controller name
    x-swagger-router-controller: movie
    get:
      description: get the movies list
      # define the type of response for Success "200" and Error
      responses:
        "200":
          description: Success
          schema:
            $ref: "#/definitions/GetMoviesListResponse"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
  /swagger:
    x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
  GetMoviesListResponse:
    required:
      - movies
    properties:
      # The array of movies
      movies:
        type: array
        items: 
          type: object
          properties:
            id:
              type: string
            title:
              type: string
            year:
              type: number
  ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string

【问题讨论】:

    标签: node.js swagger


    【解决方案1】:

    鉴于您的 YAML,并假设您使用 swagger-tools 和他们教程中给出的选项,x-swagger-router-controller: movie 会将任何对 GET /movie 的请求路由到从模块 /controllers/movie.js 导出的名为 get 的函数你的项目。你设置了吗?

    还要检查您的招摇选项以检查是否包含正确的控制器路径,例如controllers: `${__dirname}`/controllers.

    【讨论】:

      猜你喜欢
      • 2018-07-24
      • 2020-12-29
      • 2021-08-11
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 2011-11-03
      • 2021-09-17
      相关资源
      最近更新 更多