0

I'm developing a python API with flask and swagger, and I want to change one of the inputs from string to list:

This is the current working code for the schema :

   /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

and the request i'm using:

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)

This works fine, but I need To change {"question": "processor"} for:

{"question": ["processor"]}

but when I make that request I get this error:

'{\n  "detail": "[\'processor\'] is not of type \'string\'",\n  "status": 400,\n  "title": "Bad Request",\n  "type": "about:blank"\n}\n'

Hence I tried to change change the data type from string to list in the schema:

  schema:
    type: object
    properties:
      question:
        type: list
        description: question to match

But I get another error with that.

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 Answer 1

1

An array/list of strings is defined as

question:
  type: array
  items:
    type: string

type: list is not a valid value for type in OpenAPI.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.