在Swagger上,哪种是写入yaml文件的正确方法?

时间:2018-07-05 05:24:53

标签: swagger

swagger: "2.0"
info: 
  version: "1.0.0"
  title: "CCA API"
host: localhost:1337
basePath: /v1
schemes: 
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /user/login:
    post:
      description: Access a user account
      summary: User Account Access
      operationId: loginAccount
      parameters:
      - name: email
        dataType: string
        in: body
        required: true
        description: Your email
      - name: password
        dataType: string
        in: body
        required: true
        description: Your password
      responses:
        "200":
          description: Successfully signed in
          schema:
            type: object
            properties:
              email:
                type: string
              firstName:
                type: string
              lastName:
                type: string
              token:
                type: string
              userType:
                type: string
        401:
          description: Invalid email or password.

哪种是写入yaml文件的正确方法? 我收到此错误:“无效的参数定义” 在每个参数声明中...

我还想知道将Sails JS与Swagger集成的正确方法吗?

2 个答案:

答案 0 :(得分:1)

关于您的参数:我认为您必须使用“类型”,而不是“ dataType”:

参数:   -名称:电子邮件

type: string
in: body
required: true
description: Your email

-名称:密码

type: string
in: body
required: true
description: Your password

答案 1 :(得分:1)

正如Vantroys所说,dataType不是正确的密钥。它是类型。 但是在这种情况下,您尝试定义post方法,并且需要定义某种类型的输入数据,如以下示例所示。 从招摇本身看宠物商店的例子: https://editor.swagger.io/

parameters:
  - in: "body"
    name: "body"
    description: "Pet object that needs to be added to the store"
    required: true
    schema:
      $ref: "#/definitions/Pet"