我如何使用swagger模型部分?

Tho*_* R. 19 api-doc swagger

在Swagger API文档中,在apis数组旁边的json里面有一个模型对象条目,但没有关于它的文档.我该如何使用这个"模型"部分?

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

   ...

   apis: [...]
   models: {...}
}
Run Code Online (Sandbox Code Playgroud)

Cod*_*uru 18

模型只是像java中的POJO类,它们具有变量和属性.在模型部分中,您可以定义自己的自定义类,并可以将其作为数据类型引用.

如果你在下面看到

     {
        "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"
                    }
                ]
            }
Run Code Online (Sandbox Code Playgroud)

在参数部分中,它有一个参数,其dataTypePet,pet在模型中定义如下

{
"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"
            }
        }
    }
}}
Run Code Online (Sandbox Code Playgroud)

您可以拥有嵌套模型,有关更多信息,请参阅Swagger PetStore示例

所以模特只不过是类.