2016-09-10 6 views
2

私はAPIを記述するためにswaggerを使用するように求められました。より複雑な状況を処理するために苦労しています。あなたは、私がこのように配列の使用がスワッガーオブジェクトのネストした配列

/upload_order: 
post: 
    description: create order 
    operationId: upload_order 
    produces: 
    - application/xml 
    parameters: 
    - name: upload_order 
     in: body 
     description: upload order 
     required: true 
     schema: 
     $ref: '#/definitions/newOrder' 
    responses: 
    '200': 
     description: response 
     schema: 
     $ref: '#/definitions/token_response' 
    default: 
     description: unexpected error 
     schema: 
     $ref: '#/definitions/errorModel' 



newOrder: 
    type: object 
    required: 
     - token 
     - order_id 
     - item_value 
     - postage_value 
     - gross_value 
     - discount_value 
     - delivery_date 
     - customer_name 
     - business_name 
     - address_line_1 
     - address_line_2 
     - town 
     - county 
     - postcode 
     - email 
     - telephone 
     - delivery_instructions 
     - delivery_method 
     - items 
    properties: 
     token: 
     type: string 
     order_id: 
     type: string 
     item_value: 
     type: number 
     format: float 
     postage_value: 
     type: number 
     format: float 
     gross_value: 
     type: number 
     format: float 
     discount_value: 
     type: number 
     format: float 
     delivery_date: 
     type: string 
     format: date 
     customer_name: 
     type: string 
     business_name: 
     type: string 
     address_line_1: 
     type: string 
     address_line_2: 
     type: string 
     town: 
     type: string 
     county: 
     type: string 
     postcode: 
     type: string 
     email: 
     type: string 
     telephone: 
     type: string 
     delivery_instructions: 
     type: string 
     delivery_method: 
     type: string 
     items: 
     $ref: '#/definitions/itemsArray' 
    itemsArray: 
    type: array 
    required: item 
    item: 
     $ref: '#/definitions/item' 
    item: 
    required: 
     - id 
     - sku 
     - qty 
     - product_name 
     - unit_price 
    type: object 
    properties: 
     id: 
     type: string 
     sku: 
     type: string 
     qty: 
     type: integer 
     format: int32 
     product_name: 
     type: string 
     unit_price: 
     type: number 
     format: float 

をプレイしていないようですので、私を保存してください、闊歩でそれを記述することができる方法

<upload_order> 
<token>d6a91238b0f17b49d49fbdcbba773d71</token> 
<order> 
    <order_id>10006</order_id> 
    <item_value>48.50</item_value> 
    <postage_value>5.00</postage_value> 
    <gross_value>A43.50</gross_value> 
    <discount_value>10.00</discount_value> 
    <delivery_date>2016-10-32</delivery_date> 
    <customer_name>Tom H</customer_name> 
    <business_name>Toysorry</business_name> 
    <address_line_1>Adderss Line 1</address_line_1> 
    <address_line_2>Adderss Line 1</address_line_2> 
    <town>Town</town> 
    <county>County</county> 
    <postcode>PO123ST</postcode> 
    <email>[email protected]</email> 
    <telephone>0787878787878</telephone> 
    <delivery_instructions>Garage</delivery_instructions> 
    <delivery_method>PRE12</delivery_method> 
    <items> 
     <item> 
      <id>1</id> 
      <sku>BLABLA</sku> 
      <qty>A</qty> 
      <product_name>A Product</product_name> 
      <unit_price>1.50</unit_price> 
     </item> 
     <item> 
      <id>2</id> 
      <sku>HAHAHA</sku> 
      <qty>2</qty> 
      <product_name>WINTER BUNDLE</product_name> 
      <unit_price>22.00</unit_price> 
     </item> 
    </items> 
</order> 

複数の注文項目で注文を掲示している想像してみて

おかげ

UPDATE - 私は数日後にBA考え出しをSED ON FULL PET SHOPマークアップは、あなたがタイプitemsArrayを必要としないであろうと思われるXML文書に基づいてSOME

paths: 
    /upload_order: 
    post: 
     description: create order 
     operationId: upload_order 
     parameters: 
     - name: upload_order 
      in: body 
      description: upload order 
      required: true 
      schema: 
      $ref: '#/definitions/uploadOrder' 
     responses: 
     '200': 
      description: response 
      schema: 
      $ref: '#/definitions/upload_response' 
     default: 
      description: unexpected error 
      schema: 
      $ref: '#/definitions/errorModel' 
definitions: 
    uploadOrder: 
    type: object 
    required: 
     - upload_order 
    properties: 
     upload_order: 
     $ref: '#/definitions/uploadOrderData' 
    uploadOrderData: 
    type: object 
    required: 
     - login 
     - order 
    properties: 
     login: 
     $ref: '#/definitions/login' 
     order: 
     $ref: '#/definitions/order' 
    order: 
    type: object 
    required: 
     - order_id 
     - address_line_2 
     - items 
    properties: 
     order_id: 
     type: string 
     item_value: 
     type: string 
     pattern: '^(\d{1,100}\.\d{2})$' 
     default: '0.00' 
     postage_value: 
     type: string 
     pattern: '^(\d{1,100}\.\d{2})$' 
     default: '0.00' 
     gross_value: 
     type: string 
     pattern: '^(\d{1,100}\.\d{2})$' 
     default: '0.00' 
     discount_value: 
     type: string 
     pattern: '^(\d{1,100}\.\d{2})$' 
     default: '0.00' 
     delivery_date: 
     type: string 
     format: date 
     customer_name: 
     type: string 
     business_name: 
     type: string 
     address_line_1: 
     type: string 
     address_line_2: 
     type: string 
     town: 
     type: string 
     county: 
     type: string 
     postcode: 
     type: string 
     email: 
     type: string 
     telephone: 
     type: string 
     delivery_instructions: 
     type: string 
     delivery_method: 
     type: string 
     items: 
     $ref: '#/definitions/orderItems' 
    orderItems: 
    type: array 
    required: 
     - item 
    properties: 
     item: 
     $ref: '#/definitions/orderItem' 
    items: 
     $ref: '#/definitions/orderItem' 
    orderItem: 
    required: 
     - id 
     - sku 
     - qty 
     - product_name 
     - unit_price 
    type: object 
    properties: 
     id: 
     type: string 
     sku: 
     type: string 
     qty: 
     type: integer 
     format: int32 
     product_name: 
     type: string 
     unit_price: 
     type: string 
     pattern: '^(\d{1,100}\.\d{2})$' 
     default: '0.00' 
    login: 
    type: object 
    required: 
     - login 
    properties: 
     login: 
     $ref: '#/definitions/login_data' 
    login_data: 
    type: object 
    required: 
     - username 
     - password 
     - channel_code 
    properties: 
     username: 
     type: string 
     password: 
     type: string 
     channel_code: 
     type: string 
    upload_response: 
    type: object 
    properties: 
     response: 
     $ref: '#/definitions/upload_response_data' 
    upload_response_data: 
    type: object 
    required: 
     - messages 
     - success 
    properties: 
     messages: 
     $ref: '#/definitions/messages' 
     success: 
     type: string 
    errorModel: 
    type: object 
    required: 
     - messages 
    properties: 
     messages: 
     $ref: '#/definitions/messages' 
    messages: 
    type: array 
    required: 
     - message 
    properties: 
     message: 
     $ref: '#/definitions/message' 
    items: 
     $ref: '#/definitions/message' 
    message: 
    type: string 

答えて

2

のための答え、EASY POINTを投稿することを忘れていました。 itemタイプをitemsに直接参照することによって、newOrderの定義を単純化することができます。変更された型定義の関連部分を次に示します。 http://i.stack.imgur.com/MyjpD.png

追加の注記:

definitions: 
    newOrder: 
     type: object 
     ... 
     properties: 
     ... 
     delivery_method: 
      type: string 
     items: 
      type: array 
      items: 
      $ref: '#/definitions/item' 

    item: 
     ... 
     type: object 
     properties: 
     id: 
      type: string 
     ... 

は、得られたデータ構造は次のようになりますtokenがあなたのXML文書にorder要素の外にあるとして、あなたはおそらく二つにあなたのnewOrderタイプを分割しにtokenを移動する必要があります外側の要素ここでは、トークンがネストされた要素orderに移動されていることを除いて、すべてのプロパティの例を示します。

型定義を結果として生じる
newOrder: 
    properties: 
     token: 
     type: string 
     order: 
     type: array 
     items: 
      $ref: '#/definitions/order' 
    order: 
    properties: 
     order_id: 
     type: string 
     ... 

http://i.stack.imgur.com/P12Ah.png

+0

ああ男申し訳ありませんが私は私の問題は、完全なペットショップのマークアップに基づいたものを数日後に考え出したが、私はちょうど闊歩してみました実際に感謝を右私には見えます – tomhre

+0

そして、うまくいくように見える、私は別の方法でmyineをやったが、とにかく感謝 – tomhre

関連する問題