1

我是 OpenAPI 的新手,我需要一些帮助来为 PayPal 的支付 API创建一个基本的 swagger 文件,以便从我们的平台创建支付。注意:OAuth 已配置。

下面是一个基本的招摇文件,但我不知道在哪里将付款请求信息(即意图、付款人、交易等)添加到:

{
  "swagger": "2.0",
  "info": {
    "description": "this is a payment request to through PayPal",
    "title": "Swagger PayPal Payment",
    "version": "1.0.0"
  },
    "host": "api.sandbox.paypal.com",
    "basePath": "/v1/payments", //
    "schemes": [ "https" ],
  "paths": {
    "/payment":
    {
      "post": {
        "summary": "Creates a payment"
        "description": "Creates a payment request to Paypal",
        "parameters": {

        },
        //"intent": "sale",
        //"payer":
        //{
        //  "payment_method": "paypal"
        //},
        //"transactions": [
        //  {
        //    "amount": {
        //      "total": "9.00",
        //      "currency": "EUR"
        //    }
        //  }
        //],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}

在 editor.swagger 上测试文件时,我收到有关交易、付款人和意图的“OBJECT_ADDITIONAL_PROPERTIES”错误。

4

1 回答 1

2

JSON 有效负载被定义为一个主体参数(带有 的参数in: body),该参数需要一个schema定义 JSON 对象属性的参数。您通常会在全局definitions部分定义对象模式并使用$ref.

这是可读性的 YAML 版本。要将其转换为 JSON,请将其粘贴到http://editor.swagger.io并使用 File > Download JSON。

swagger: "2.0"
info:
  description: this is a payment request to through PayPal
  title: Swagger PayPal Payment
  version: "1.0.0"

host: api.sandbox.paypal.com
basePath: /v1/payments
schemes: [ https ]

paths:
  /payment:
    post:
      summary: Creates a payment
      description: Creates a payment request to Paypal
      parameters:
        - in: body
          name: payment
          required: true
          schema:
            $ref: "#/definitions/Payment"   # <--------
      responses:
        "200":
          description: OK

definitions:

  # Request body object
  Payment:
    type: object
    properties:
      intent:
        type: string
      payer:
        $ref: "#/definitions/Payer"
      transactions:
        type: array
        items:
          $ref: "#/definitions/Transaction"

  Payer:
    type: object
    properties:
      payment_method:
        type: string
        example: paypal

  Transaction:
    type: object
    properties:
      ... # TODO
于 2017-03-17T08:23:45.777 回答