2013-03-04 32 views
16

在Swagger API文檔中,在json內部的apis數組旁邊有一個模型對象條目,但沒有關於它的文檔。我怎樣才能使用這個「模型」部分?如何使用swagger模型部分?

{ 
    apiVersion: "0.2", 
    swaggerVersion: "1.1", 
    basePath: "http://petstore.swagger.wordnik.com/api", 
    resourcePath: "/pet.{format}" 

    ... 

    apis: [...] 
    models: {...} 
} 

回答

16

模型只不過是像你的POJO類在Java中有變量和屬性。在模型部分中,您可以定義自己的自定義類,並且可以將其引用爲數據類型。

如果你看到下面

 { 
     "path": "/pet.{format}", 
     "description": "Operations about pets", 
     "operations": [ 
      { 
       "httpMethod": "POST", 
       "summary": "Add a new pet to the store", 
       "responseClass": "void", 
       "nickname": "addPet", 
       "parameters": [ 
        { 
         "description": "Pet object that needs to be added to the store", 
         "paramType": "body", 
         "required": true, 
         "allowMultiple": false, 
         "dataType": "Pet" 
        } 
       ], 
       "errorResponses": [ 
        { 
         "code": 405, 
         "reason": "Invalid input" 
        } 
       ] 
      } 

在這裏,在參數部分它有一個參數是誰的的dataType寵物和寵物在模型定義如下

{ 
"models": { 
    "Pet": { 
     "id": "Pet", 
     "properties": { 
      "id": { 
       "type": "long" 
      }, 
      "status": { 
       "allowableValues": { 
        "valueType": "LIST", 
        "values": [ 
         "available", 
         "pending", 
         "sold" 
        ] 
       }, 
       "description": "pet status in the store", 
       "type": "string" 
      }, 
      "name": { 
       "type": "string" 
      }, 
      "photoUrls": { 
       "items": { 
        "type": "string" 
       }, 
       "type": "Array" 
      } 
     } 
    } 
}} 

可以嵌套型號,欲瞭解更多信息請參閱Swagger PetStore example

S o模型只不過是類。

相關問題