我正在使用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
答案 0 :(得分:0)
鉴于您的YAML,并假设您使用swagger-tools其教程中提供的选项,x-swagger-router-controller: movie
会将任何请求GET /movie
发送到名为get
的函数从项目中的模块/controllers/movie.js
导出。你准备好了吗?
同时检查您的招摇选项以检查是否包含正确的控制器路径,例如controllers: `${__dirname}`/controllers
。