gpt4 book ai didi

python - Flask-RESTPlus - 嵌套字段未注册到 SwaggerUI 中

转载 作者:太空宇宙 更新时间:2023-11-03 20:54:57 25 4
gpt4 key购买 nike

我正在尝试为响应模型创建一个嵌套字段。我不明白为什么生成的 swagger.json 知道嵌套字段,但不在 $/definitions 下注册它。

这是我的模型

HypervisorResponse = ns.model('HypervisorResponse', {
'name': fields.String(required=True, example='hypervisor01.xx.com'),
'ip_addr': fields.String(required=True, example='192.168.0.0'),
'provider': fields.String(required=True),
'runtime': fields.Nested(
ns.model('RuntimeResponse', {
'uptime': fields.Integer(attribute='uptime'),
'last_boot': fields.String(attribute='last_boot'),
'memory_total': fields.Integer(attribute='memory_total'),
'memory_used': fields.Integer(attribute='memory_used')
})
)
})

输出的swagger.json为

        "HypervisorResponse": {
"required": [
"ip_addr",
"name",
"provider"
],
"properties": {
"name": {
"type": "string",
"example": "hypervisor01.xx.com"
},
"ip_addr": {
"type": "string",
"example": "192.168.0.0"
},
"provider": {
"type": "string"
},
"runtime": {
"$ref": "#/definitions/RuntimeResponse"
}
},
"type": "object"
}

最佳答案

过了一段时间,我发现 NAMESPACE 有序属性是造成这种情况的原因。将其设置为 False 解决了该问题。

关于python - Flask-RESTPlus - 嵌套字段未注册到 SwaggerUI 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56079764/

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