我使用Swagger来构建Rest Api。端点之一是/ register,它在swagger.yaml中定义如下:
/register:
post:
tags:
- "User"
summary: "Registers the User"
description: "..."
operationId: "register_user"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "username"
description: "Register data"
required: true
schema:
$ref: "#/definitions/username_1"
responses:
201:
description: "User registered."
404:
description: "invalid input, object invalid"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
和对象的定义:
username_1:
type: "object"
properties:
username:
type: "string"
password:
type: "string"
email:
type: "string"
language:
type: "string"
register_user函数什么都不做。
def register_user(self):
return 'do some magic!'
在邮递员中,我在“身体形式数据”字段中添加值:
KEY VALUE
username a
password a
email a
language a
在发送后我会收到
{
"detail": "None is not of type 'object'",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}.
据我所知,到目前为止,问题是尸体不是通过邮递员发送的。如果我更改了定义
username_1:
type: "string"
#properties:
#username:
#type: "string"
#password:
#type: "string"
#email:
#type: "string"
#language:
#type: "string"
将字符串转换为错误的对象
"None is not of type 'string'".
以下是邮递员配置https://i.stack.imgur.com/E7udd.png和标头https://i.stack.imgur.com/Evkcr.png之一的屏幕截图
作为最后的观察,GET请求(不需要其他参数即可完美运行)。 您有解决问题的想法吗?非常感谢!