gpt4 book ai didi

swagger - 我如何使用 Swagger 模型部分?

转载 作者:行者123 更新时间:2023-12-03 12:52:29 34 4
gpt4 key购买 nike

在Swagger API文档中,在apis数组旁边的json内有一个模型对象条目,但没有关于它的文档。如何使用“模型”部分?

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

...

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

最佳答案

模型只不过是您的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"
}
]
}


在参数部分中,它具有一个参数,其dataType为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"
}
}
}
}}


您可以具有嵌套模型,有关更多信息,请参见 Swagger PetStore example

因此模型不过是类。

关于swagger - 我如何使用 Swagger 模型部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197579/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com