Skip to content

Arrays are parsed incorrectly with multipart/form-data #1869

@alfechner

Description

@alfechner

Description

I use multipart/form-data with a property bar which is of type array. The encoding is set to application/json. The spec looks like this:

openapi: 3.0.3
info:
  title: LIQUID Dataset Service
  version: 1.0.0
paths:
  /foo:
    post:
      x-openapi-router-controller: liquid_dataset_service.controllers.dataset_controller
      operationId: create_bar
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                bar:
                  type: array
                  items:
                    type: object
                    properties:
                      baz:
                        type: string
              required:
                - bar
            encoding:
              bar:
                contentType: application/json
      responses:
        204:
          description: No Content

Expected behaviour

When running the request I'd expect to get the bar property passed into the body argument of my controller function.

Actual behaviour

Server raises error: Validation error: '["{\\n \\"baz\\": \\"string\\"\\n}"]' is not of type 'object' - 'bar.0'.

To me it looks like that the string is not properly parsed if it's an array. To verify I changed the type of bar from array of object's to array of string's:

bar:
  type: array
  items:
    type: string

I passed two strings "one" and "two" and received this dict in my controller function: {'bar': ['["one"', '"two"]']}.

Steps to reproduce

Create a controller function, e.g.:

def create_bar(body):
    return

Adjust property x-openapi-router-controller accordingly.

Fire up the swagger page or use curl to run the request.

Additional info:

Output of the commands:

  • python --version: Python 3.11.6
  • pip show connexion | grep "^Version\:": Version: 3.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions