2016-03-31 8 views
0

私はSwagger 1.2を使用しています。JSONネストしたオブジェクトをモデル化しようとするのは苦労します。モデルスキーマをスワッガーオンラインデモペットショップPOST /ペット(サンプル値)例えば、私のオブジェクトは、次のとおりです。Swagger-1.2:モデルスキーマでn-nested JSONオブジェクトを表示する方法

{ 
    "parent" : { 
     "child_1" : { 
      "child_2a" : "string", 
      "child_2b" : { 
       "child_3a" : "string", 
       "child_3b" : ["string"] 
      } 
     } 
    } 
} 

あなたが見ることができるように、私は以上の1つのレベルのJSONを持っています。

.... 
stuff here 
..... 
api: [ 
{ 
      "path": "/api/foo/bar", 
      "operations": [ 
       { 
        "method": "POST", 
        "summary": "a job", 
        "consumes": ["application/json"], 
        "authorizations": {}, 
        "parameters": [ 
         { 
          "name": "body", 
          "required": true, 
          "type" : "Parent", 
          "description": "some description", 
          "paramType": "body" 
         }, 
         { 
          "name": "fooz", 
          "description": "some description", 
          "required": false, 
          "type": "string", 
          "paramType": "query" 
         } 
        ], 
        ...... 
        ........ 
     } 
], 
"models" : { 
    "Parent": { 
      "id": "Parent", 
      "required": ["parent"], 
      "properties": { 
       "parent": { 
       "$ref": "Child1" 
       } 
      } 
     }, 
     "Child1": { 
      "id": "Child1", 
      "required" : ["child_1"], 
      "properties": { 
       "child_1": { 
       "$ref": "Child2" 
       } 
      } 
     }, 

     "Child2" : { 
      "id" : "Child2", 
      "required" : ["child_2a", "child_2b"], 
      "properties" : { 
       "child_2a" : { 
        "type" : "string" 
       }, 
       "child_2b" : { 
        "$ref" : "Child3" 
       } 

      } 
     }, 
     "Child3" : { 
      "id" : "Child2", 
      "required" : ["child_3a", "child_3b"], 
      "properties" : { 
       "child_3a" : { 
        "type" : "string" 
       }, 
       "child_3b" : { 
        "type" : "array", 
        "items": { 
         "type": "string" 
        } 
       } 
     } 

} 

しかし、モデルスキーマの表示は次のとおりです:私のparameterアレイでは、私はこのような何か持って

{ 
    "parent" : "Child1" 
} 

を私はおそらく間違った何かをしましたか? Model Schemaにネストされたオブジェクト全体を表示するにはどうすればよいですか? SwaggerデモペットストアのようにPOST/Pet Example Value

答えて

0

Swagger 1.2では、モデル定義全体をフラットにする必要があります。つまり、ネストされた複雑なオブジェクト、プリミティブと他の複雑なオブジェクトへの参照はできません。

swagger 2.0以降、インライン、ネスト、または匿名のオブジェクトを使用できるようになりました。

簡単な答えは、1.2で説明していることをモデル化できないということです。できる場合は、swagger 2.0を使用するようにライブラリを更新することを検討してください。

+0

ご清聴ありがとうございます。 – leona

関連する問題