xtiger
xtiger

Reputation: 1446

Swagger validation failed in Yaml file

I have a swagger yaml specification like this :

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

This yaml file is compiled well without the header part. If I include the header in the paramerts . The nodejs app keep throwing : "Swagger validation errors"

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

I don't know what was wrong in this part. I want to add the header to this spec file.

Upvotes: 2

Views: 1187

Answers (1)

fehguy
fehguy

Reputation: 6824

You simply need to add the type attribute. Swagger doesn't know if this is a string, an integer, etc. (although one could say the default explains it).

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

Upvotes: 3

Related Questions