Skip to content

RequestBody with both form-data and json payload does not work #1193

@ohurley

Description

@ohurley

Description

I am trying to upload an audio file. The content contains the a file (form-data) and my schema component (application/json). The code can read the file but it cannot identify the json

Could you provide me with an example spec that can cater for this functionality?

Expected behaviour

I added content for both application/json & multipart/form-data (or audio/*) and the request proceeds without error

Actual behaviour

It fails on validation against the json payload

{
    "_schema": [
        "Invalid input type."
    ]
}

The reason for this is that get_json() method returns None. It looks like connexion does not like 2 different requestBody components

Additional info:

Code snippet

def put():
    req_data = request.get_json()
    errors = None
    try:
        data = task_schema.load(req_data)  # , partial=True)
    except ValidationError as err:
        errors = err.messages  # It throws the error
       

spec:

    put:
      tags:
        - Tasks
      summary: Endpoint to create new or update existing Task object
      operationId: resources.task.put
      responses:
        '200':
          description: Updated
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '202':
          description: Patient has not been created yet
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Task'
          audio/*:
            schema:
              type: string
              format: binary


....

Task:
      type: object
      properties:
        t_id:
          type: string
          description: Unique identifier for a Task object
          example: '2305a17b-6aa0-4250-9c60-e9828f493057'
        a_id:
          type: string
          description: Unique identifier for a Assessment object (FK)
          example: '2305a17b-6aa0-4250-9c60-e9828f493057'
        t_type:
          type: string
          description: Task type
          example: 'T1'
        description:
          type: string
          description: Task name
          example: ' Sustaining vowel– a'
        uri:
          type: string
          description: Storage location for the audio recording file
          example: 'aws:bucket/assessments/file.wav'
        created:
          type: string
          format: date-time
          description: Creation time
          example: '2015-07-07T15:49:51.230+02:00'
        modified_at:
          type: string
          format: date-time
          description: Creation time
          example: '2015-07-07T15:49:51.230+02:00'
#        fileName:
#          type: object
#          description: file
#          properties:
#            content-type:
#              type: 'application/octet-stream'

Output of the commands:

  • python --version
    Python 3.6.8
  • pip show connexion | grep "^Version\:"
    Version: 2.4.0

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