Python 你能把招摇过市和#x27;查询和正文中的参数?
我在尝试时遇到错误,但我想创建一个端点,该端点接受2个查询参数和1个主体项,即名称列表。当我在connexion中运行它,但说它是无效规范时Python 你能把招摇过市和#x27;查询和正文中的参数?,python,swagger,swagger-2.0,connexion,Python,Swagger,Swagger 2.0,Connexion,我在尝试时遇到错误,但我想创建一个端点,该端点接受2个查询参数和1个主体项,即名称列表。当我在connexion中运行它,但说它是无效规范时 /devices/list: post: tags: [Devices] operationId: app.get_devices summary: Gets a complete list of devices. parameters: - $ref: '#/parameters/foo-t'
/devices/list:
post:
tags: [Devices]
operationId: app.get_devices
summary: Gets a complete list of devices.
parameters:
- $ref: '#/parameters/foo-t'
- $ref: '#/parameters/bar-t'
- in: body
name: device_names
required: true
type: array
items:
type: string
description: a list of devices
...
它编译和运行时没有-in:body部分。所以我知道这两个参数都很好。似乎我在将json数组应用于python时遇到了问题
显式返回的错误为:
connexion.exceptions.InvalidSpecification:{'in':'body','name':
'device_names','required':True,'type':'array','items':{'type':
'string'},'description':'A list of Device Names'}在下无效
任何给定的模式
验证中的“其中一个”失败
架构['properties']['Path']['patternProperties']['^/']['properties']['post']['properties']['parameters']['items']:
{'oneOf':[{'$ref':'#/definitions/parameter'},
{'$ref':'#/definitions/jsonReference'}]}
在实例['path']['/devices/list']['post']['parameters'][2]上:
{'description':'设备名称列表',
‘in’:‘body’,
'items':{'type':'string'},
“名称”:“设备名称”,
“必需”:True,
'type':'array'}
我想要的结局是我可以说:
//In javascript
$.post("devices/list", {device_names: ["a","b","c"]}, {params:{foo:1, bar:42}}).success( x => {
//...
});
# In Python3
def get_devices(foo, bar, device_names):
pass
是的,您可以混合查询和主体参数 错误是由body参数的语法不正确引起的。更改它,以便将
类型
和项
包装到架构
,如下所示:
-in:body
名称:设备名称
必填项:true
架构:#错误文本不包含“架构”
,因此它似乎与旧定义匹配。你能再检查一下connexion是否使用了更新后的定义吗?请稍等,我看一下:)它看起来不像是类型:array创建的,它不是有效的application/json。它似乎正在尝试发布以行分隔的字符串。是否有一种夸张的方式将其封装为有效的json?示例:{“设备名称”:[“foo”,“bar”]}