2017-02-07 9 views
0

私はいくつかの他の関連する質問を見てきましたが、私はまだ私が探しているものを見つけることができないようです。すべての始まりのパラメータを記述このJSONオブジェクトは、どのように記述すればよいですか?

{ 
    "publishType": "Permitable", 
    "electricalPanelCapacity": 0.0, 
    "roofConstruction": "Standard/Pitched", 
    "roofType": "Composition Shingle", 
    "systemConstraint": "None", 
    "addedCapacity": 0.0, 
    "isElectricalUpgradeRequired": false, 
    "cadCompletedBy": "94039", 
    "cadCompletedDate": "2017-02-01T02:18:15Z", 
    "totalSunhourDeficit": 5.0, 
    "designedSavings": 5.0, 
    "isDesignedWithinTolerance": "N/A", 
    "energyProduction": { 
     "january": 322.40753170051255, 
     "february": 480.61501312589826, 
     "march": 695.35215022905118, 
     "april": 664.506907341219, 
     "may": 877.53769491124172, 
     "june": 785.56924358327, 
     "july": 782.64347308783363, 
     "august": 760.1123565793057, 
     "september": 574.67050827435878, 
     "october": 524.53797441350321, 
     "november": 324.31132291046379, 
     "december": 280.46921069200033 
    }, 
    "roofSections": [{ 
     "name": "North East Roof 4", 
     "roofType": "Composition Shingle", 
     "azimuth": 55.678664773137086, 
     "tilt": 15.0, 
     "solmetricEstimate": 510.42831656979456, 
     "shadingLoss": 14.0, 
     "systemRating": 580.0, 
     "sunHours": 0.88004882167205956, 
     "moduleCount": 2, 
     "modules": [{ 
      "moduleRating": 290.0, 
      "isovaPartNumber": "CDS-MON-007070", 
      "partCount": 2 
     }] 
    }, { 
     "name": "South West Roof 3", 
     "roofType": "Composition Shingle", 
     "azimuth": 235.67866481720722, 
     "tilt": 38.0, 
     "solmetricEstimate": 3649.1643776261653, 
     "shadingLoss": 59.0, 
     "systemRating": 5220.0, 
     "sunHours": 0.69907363556056812, 
     "moduleCount": 18, 
     "modules": [{ 
      "moduleRating": 290.0, 
      "isovaPartNumber": "CDS-MON-007070", 
      "partCount": 18 
     }] 
    }, { 
     "name": "South East Roof", 
     "roofType": "Composition Shingle", 
     "azimuth": 145.67866477313709, 
     "tilt": 19.0, 
     "solmetricEstimate": 2913.1406926526984, 
     "shadingLoss": 31.0, 
     "systemRating": 2900.0, 
     "sunHours": 1.0045312733285168, 
     "moduleCount": 10, 
     "modules": [{ 
      "moduleRating": 290.0, 
      "isovaPartNumber": "CDS-MON-007070", 
      "partCount": 10 
     }] 
    }], 
    "SystemConfiguration": { 
     "inverters": [{ 
      "isovaPartNumber": "ENP-INV-007182", 
      "partCount": 30 
     }] 
    } 
} 

は簡単だった:これは私が書いているAPIに送信されている例JSONペイロードです。

/post/new-cad/{serviceNumber}: 
    post: 
     summary: Publish a new CAD record. 
     description: Creates a new CAD record under the provided service number and returns the name of the new CAD record, the unique SF ID, and the deep link URL for Salesforce. 
     parameters: 
     - name: serviceNumber 
      in: path 
      description: The service number for the solar project you're interested in publishing to. 
      required: true 
      type: string 
     - name: publishType 
      in: formData 
      description: The type of CAD record to publish (Proposal, Permitable, or AsBuilt). 
      required: true 
      type: string 
     - name: electricalPanelCapacity 
      in: formData 
      required: true 
      type: number 
      format: double 
     - name: roofConstruction 
      in: formData 
      description: New, Flat Roof, Open Beam, Standard/Pitched 
      required: true 
      type: string 
     - name: roofType 
      in: formData 
      description: Composition Shingle, Membrane (Rubber, TPO, PVC, EPDM), Metal - Corrugated (S-Curve), Metal - Standing Seam, Metal - Trapezoidal, Multi Roof Type, Rolled Comp, Silicone, Tar & Gravel, Tile - Flat, Tile - S-Curve, or Tile - W-Curve 
      type: string 
     - name: systemConstraint 
      in: formData 
      description: Usage, None, Roof, Electrical, Shading, or 10kW Max 
      required: true 
      type: string 
     - name: addedCapacity 
      in: formData 
      required: true 
      type: number 
      format: double 
     - name: isElectricalUpgradeRequired 
      in: formData 
      type: boolean 
     - name: cadCompletedBy 
      in: formData 
      description: Employee ID of record author. 
      type: number 
      required: true 
     - name: cadCompletedDate 
      in: formData 
      description: The date the CAD record was completed. 
      type: string 
      format: date 
      required: true 
     - name: totalSunhourDeficit 
      in: formData 
      type: number 
      format: double 
     - name: designedSavings 
      in: formData 
      type: number 
      format: double 
     - name: isDesignedWithinTolerance 
      in: formData 
      type: string 
      description: Yes, No, or N/A 

と威張っ-UIで期待される結果が得られます

しかし、今、私は上記の例JSONペイロードの最後の部分に苦しんだが。私は、月の毎月のキーを持つオブジェクトであるenergyProductionのキーを表現する方法が不明です。私はまた、オブジェクトの配列であるroofSectionsを記述する方法が不明であり、値がオブジェクトの配列であるinvertersというプロパティを持つオブジェクトであるsystemConfigurationがあります。

私はswagger documentationをかなり上回っていますが、私はまだかなり混乱していて、ここの誰かが私に少しうまく説明できると思っています。

答えて

1

私はそれを理解しました。 formDataが私のパラメータに使用していたはずのものではありません。その代わりに、私はbodyを使用して、本文に移入するJSONの構造を定義する必要がありました。完成したデザインファイルは、bodyパラメータをオブジェクトスキーマとともに使用し、すべてのネストされたオブジェクトと配列も記述します。

/new-cad/{serviceNumber}: 
    post: 
     summary: Publish a new CAD record. 
     description: Creates a new CAD record under the provided service number and returns the name of the new CAD record, the unique SF ID, and the deep link URL for Salesforce. 
     parameters: 
     - name: serviceNumber 
      in: path 
      description: The service number for the solar project you're interested in publishing to. 
      required: true 
      type: string 
     - name: cadData 
      in: body 
      description: A JSON payload containing the data required to publish a new CAD record. 
      required: true 
      schema: 
      type: object 
      properties: 
       publishType: 
       type: string 
       default: "Proposal" 
       enum: ["Proposal","Permitable","AsBuilt"] 
       electricalPanelCapacity: 
       type: number 
       roofConstruction: 
       type: string 
       default: "New" 
       enum: ["New","Flat Roof","Open Beam","Standard/Pitched"] 
       roofType: 
       type: string 
       enum: ["Composition Shingle","Membrane (Rubber, TPO, PVC, EPDM)","Metal - Corrugated (S-Curve)","Metal - Standing Seam","Metal - Trapezoidal","Multi Roof Type","Rolled Comp","Silicone","Tar & Gravel","Tile - Flat","Tile - S-Curve","Tile - W-Curve"] 
       systemConstraint: 
       type: string 
       default: "None" 
       enum: ["None","Usage","Roof","Electrical","Shading","10kW Max"] 
       addedCapacity: 
       type: number 
       default: 0 
       isElectricalUpgradeRequired: 
       type: boolean 
       cadCompletedBy: 
       type: string 
       cadCompletedDate: 
       type: string 
       totalSunhourDeficit: 
       type: number 
       designedSavings: 
       type: number 
       isDesignedWithinTolerance: 
       type: string 
       default: "N/A" 
       enum: ["N/A","Yes","No"] 
       energyProduction: 
       type: object 
       properties: 
        january: 
        type: number 
        february: 
        type: number 
        march: 
        type: number 
        april: 
        type: number 
        may: 
        type: number 
        june: 
        type: number 
        july: 
        type: number 
        august: 
        type: number 
        september: 
        type: number 
        october: 
        type: number 
        november: 
        type: number 
        december: 
        type: number 
       roofSections: 
       type: array 
       items: 
        type: object 
        properties: 
        name: 
         type: string 
        roofType: 
         type: string 
         enum: ["Composition Shingle","Membrane (Rubber, TPO, PVC, EPDM)","Metal - Corrugated (S-Curve)","Metal - Standing Seam","Metal - Trapezoidal","Multi Roof Type","Rolled Comp","Silicone","Tar & Gravel","Tile - Flat","Tile - S-Curve","Tile - W-Curve"] 
        azimuth: 
         type: number 
        tilt: 
         type: number 
        solmetricEstimate: 
         type: number 
        shadingLoss: 
         type: number 
        systemRating: 
         type: number 
        sunHours: 
         type: number 
        moduleCount: 
         type: integer 
        modules: 
         type: array 
         items: 
         type: object 
         properties: 
          moduleRating: 
          type: number 
          isovaPartNumber: 
          type: string 
          partCount: 
          type: integer 
       systemConfiguration: 
       type: object 
       properties: 
        inverters: 
        type: array 
        items: 
         type: object 
         properties: 
         isovaPartNumber: 
          type: string 
         partCount: 
          type: integer 
     tags: 
     - NEW-CAD 
     responses: 
     200: 
      description: CAD record created successfully. 
      schema: 
      type: object 
      properties: 
       cadName: 
       type: string 
       sfId: 
       type: string 
       sfUrl: 
       type: string 
      examples: 
      cadName: some name 
      sfId: a1o4c0000000GGAQA2 
      sfUrl: http://some-url-to-nowhere.com 
     204: 
      description: No project could be found for the given service number. 
     500: 
      description: Unexpected error. Most likely while communicating with Salesforce. 
      schema: 
      type: string 

他のすべてがリクエストボディにしていながら、だから今、私はまだパスからserviceNumberを得ることができます。ここで心に留めておくべきことの1つは、すべて同じものを使用することができないということです。Swagger Data Typesたとえば、プロパティの1つにdoubleを使用しようとしましたが、Swaggerはタイプdoubleを解析できないと訴えました。 formDataパラメータとbodyパラメータの間の違いを説明しているthe section of the docs(最終的には要求本体全体を記述しているため、1つしか持てません)が見つかるまで、私は非常に混乱しました。基本的には、JSONスキーマでサポートされているデータ型しか使用できません。

闊歩-UIは、現在代わりに、各パラメータのための複数の入力フィールドの単一のテキストエリアを示しています。それほど美しいものではありませんが、素晴らしい作品です。右側の "Example Value"ボックスをクリックすると、定義済みのJSONテンプレートがテキストエリアに配置され、値を入力できます。

あなたがスワッガーを習っているのなら、私はこれが助けてくれることを願っています!

関連する問題