2017-02-20 57 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