我正在使用flask和swagger开发一个python API,我想将其中一个输入从字符串更改为列表:
这是架构的当前工作代码:
/question:
post:
operationId: processor.convertInputString
tags:
- People
summary: Create a person and add it to the people list
description: Create a new person in the people list
parameters:
- name: input_string_2
in: body
description: Person to create
required: True
schema:
type: object
properties:
question:
type: list
description: question to match
responses:
201:
description: Successfully created person in list
和我正在使用的请求:
data = {"question": "processor","num_results":3}
headers = {'content-type': 'application/json'}
url = "http://localhost:5000/api/question"
data = requests.post(url,data=json.dumps(data), headers=headers)
这很好用,但我需要将 {"question": "processor"} 更改为:
{"question": ["processor"]}
但是当我提出这个请求时,我得到了这个错误:
'{\n "detail": "[\'processor\'] is not of type \'string\'",\n "status": 400,\n "title": "Bad Request",\n "type": "about:blank"\n}\n'
因此,我尝试将模式中的数据类型从字符串更改为列表:
schema:
type: object
properties:
question:
type: list
description: question to match
但我得到了另一个错误。
Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['post']['properties']['parameters']['items']:
{'oneOf': [{'$ref': '#/definitions/parameter'},
{'$ref': '#/definitions/jsonReference'}]}
On instance['paths']['/question']['post']['parameters'][0]:
{'description': 'Person to create',
'in': 'body',
'name': 'input_string_2',
'required': True,
'schema': {'properties': {'question': {'description': 'question to '
'match',
'type': 'list'}},
'type': 'object'}}