python中列表的大张旗鼓的validadtion错误

时间:2019-06-11 20:47:53

标签: python api flask swagger

我正在使用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'}}

1 个答案:

答案 0 :(得分:1)

字符串数组/列表定义为

from util import module1, module2, module3, module4

var data = [[1,2,3],[4,5,6],[7,8,9]] struct ForTesting : View { var body: some View { VStack { ForEach(data.identified(by: \.self)) { array in ForEach(array.identified(by: \.self)) { element in Text("\(element)") } } } } } 在OpenAPI中不是question: type: array items: type: string 的有效值。