Yaml 文件中的 Swagger 验证失败

Swagger validation failed in Yaml file

我有一个像这样的大摇大摆的 yaml 规范:

swagger: "2.0"
info:
  version: "0.0.1"
  title: Chat API
# during dev, should point to your local machine
host: localhost:5000
# basePath prefixes all resource paths 
basePath: /api/v2
# 
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:
  /room:
    post:
      summary: Get room
      operationId: getRoom
      tags:
        - room
      parameters: 
          -
            name: token
            in: header
            description: "token to be passed as a header"
            default: "ZjE4YjMxNmY3OGEzNDMyN2JiYjJmYTQwMDBjODg4OWM="
            required: true

          -
            name: room_id
            in: body
            description: "get room"
            required: true
            schema:
              $ref: "#/definitions/Room" 

definitions:
  Room:
    required:
      - room_id
    properties:
      room_id:
        type: string

这个yaml文件没有header部分编译的很好。如果我在 paramerts 中包含 header 。 nodejs 应用程序不断抛出:"Swagger validation errors"

-
        name: token
        in: header
        description: "token to be passed as a header"
        default: "ZjE4YjMxNmY3OGEzNDMyN2JiYjJmYTQwMDBjODg4OWM="
        required: true

我不知道这部分有什么问题。我想将 header 添加到此规范文件。

您只需添加 type 属性。 Swagger 不知道这是一个字符串、一个整数等(尽管可以说 default 解释了它)。

- name: token
  in: header
  description: "token to be passed as a header"
  default: "ZjE4YjMxNmY3OGEzNDMyN2JiYjJmYTQwMDBjODg4OWM="
  required: true
  type: string