在Swagger中创建API规范时出现“未知错误”

时间:2018-04-07 09:38:07

标签: node.js swagger

您好我正在使用swagger创建一个Sample API Spec,如下所示:

我不断收到“未知错误”项:“行

swagger: "2.0"
info:
  version: "0.0.1"
  title: Todo API
# 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:
  /:
   get:
      description: "this endpoint returns list of todo events"
      operationId: "GetAllTodos"
      parameters:  []
      responses:
        200:
          description: "an array of all the present todos"
          schema:
              type: "array"
              items: 
                $ref: "#definitions/Todo"
      x-swagger-router-controller: "GetAllTodos"
  /swagger:
    x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
 Todo:
  type: "object"
  properties: 
    todo_id:
      type: "integer"
      description: "id of the todo event"
    todo:
      type: "string"
      description: "The todo item"
    datecreated:
      type: "string"
      format: "date-time"
      description: "timestamp when the todo event was created"
    author:
      type: "string"
      description: "owner of the todo event"
    duedate:
      type: "string"
      format: "date-time"
      description: "time by when the todo event should be completed"
    completed:
      type: "boolean"
      description: "status of todo completion"

enter image description here

1 个答案:

答案 0 :(得分:1)

更改

$ref: "#definitions/Todo"

$ref: "#/definitions/Todo"

请注意/之后的#

此外,您使用的旧版Swagger Editor(2.x)已不再维护。请考虑使用http://editor.swagger.io上的最新版本。