python - 请求失败,因为缺少“default_body”
问题描述
我使用 swagger-codegen 来生成 Flask-Connexion 服务器存根。这通常很好用,但我的 POST 方法失败了。检查代码显示,在 中openapi._get_body_argument()
,default_body
是一个空字典,导致行中的异常
body_arg = deepcopy(default_body)
body_arg.update(body or {})
(更新调用失败并显示“TypeError:无法将字典更新序列元素#0 转换为序列”,因为default_body
它body_arg
是空的)。
这是什么default_body
?我该怎么做才能确保正确填充?
一些元数据:我正在使用 swagger-codegen V3.0.29、Connexion V2.6(行为与 V2.9 相同)、Flask V1.1.4 和 Werkzeug V1.0.1。可以通过为标准“宠物商店”示例生成代码来观察该行为。
架构:
components:
schemas:
Tag:
type: object
properties:
tag_id:
type: string
name:
type: string
parent_id:
type: string
example:
tag_id: "42"
name: "My tag"
parent_id: "2"
操作定义:
paths:
/tag:
post:
tags:
- tag
summary: Add a new tag
operationId: add_tag
requestBody:
description: The new tag
content:
application/json:
schema:
$ref: '#/components/schemas/Tag'
application/xml:
schema:
$ref: '#/components/schemas/Tag'
required: true
responses:
"405":
description: Invalid input
content: {}
security:
- BasicAuth: []
x-codegen-request-body-name: body
x-openapi-router-controller: swagger_server.controllers.tag_controller
解决方案
推荐阅读
- javascript - chartjs 3.0 中的 generateLegend() 发生了什么?
- types - 什么时候只有在运行时才知道类型?
- android - Android 动态功能是否与应用共享类路径?
- rust - 为结构、向量和函数借用多个可变变量
- javascript - 更改选项卡时 document.getElementById({IDHERE}).style.color 不起作用
- reactjs - 将 Polymer Web 组件集成到用 Typescript 编写的 React 应用程序中?
- c++ - 在 RcppParallel 中访问开始和结束(例如计算向量的平均值)
- node.js - 分配给猫鼬枚举的打字稿枚举?
- javascript - 国庆节排除在 JQuery 中不起作用
- azure-devops - TF400813: 在 Azure DevOps 管道中使用 System.AccessToken 时,用户 '' 无权访问此资源