2017-02-20 115 views
0

我是OpenAPI的新手,我需要一些帮助来创建PayPal的payment API的基本招摇档案,以从我们的平台创建支付。 注意:OAuth已配置。PayPal支付API的Swagger格式

下面是一个基本的招摇文件,但我不知道在哪里添加paymet request information(即意图,付款人,交易等)为:

{ 
    "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”错误。

+0

有人为PayPal API编写了一个swagger格式文件吗? – Jnr

+0

看来RESTUnited是一个不错的选择。 – Jnr

回答

1

JSON有效负载定义为body parameter(参数为in: body),并且此参数需要定义JSON对象属性的schema。 您通常会在全局definitions部分中定义对象模式,并使用$ref来引用它们。

这是用于可读性的YAML版本。要将其转换为JSON,请将其粘贴到http://editor.swagger.io中,然后使用文件>下载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