2013-03-04 29 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模型只不过是类。

相关问题