Swagger 如何使用“招摇模型”部分?
在Swagger API文档中,API数组旁边的json中有一个模型对象条目,但没有关于它的文档。我如何使用这个“模型”部分Swagger 如何使用“招摇模型”部分?,swagger,api-doc,Swagger,Api Doc,在Swagger API文档中,API数组旁边的json中有一个模型对象条目,但没有关于它的文档。我如何使用这个“模型”部分 模型与java中具有变量和属性的POJO类非常相似。在“模型”部分中,您可以定义自己的自定义类,并将其作为数据类型引用 如果你看到下面 { "path": "/pet.{format}", "description": "Operations about pets", "operations": [
模型与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"
}
]
}
在参数部分,有一个参数的数据类型为Pet,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"
}
}
}
}}
可以使用嵌套模型,有关详细信息,请参见
所以模型只不过是类
{
"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"
}
}
}
}}