Skip to content

_get_kwargs does not produce correct payload when there are data and files present #508

Closed
@skuo1-ilmn

Description

@skuo1-ilmn

Describe the bug
When an API endpoint accepts data and files as a part of a multipart form data, the generated code puts the data fields (expected by httpx) into files, which leads to a TypeError in httpx when trying to encode the multipart form data.

To Reproduce
Steps to reproduce the behavior:

  1. Generate client
  2. Try to use the endpoint

Expected behavior
Should not encounter TypeError in httpx. More specifically, the _get_kwargs() function of the module for the endpoint needs to return an additional field, data, in addition to files for the plain text fields. That probably means multipart_data.to_multipart() should return both data and files. Currently, it only returns files.

OpenAPI Spec File
The openapi.yaml is private, but I can do my best to produce a snippet that would reproduce the error. The actual endpoint shouldn't matter because the TypeError is encountered before sending any requests.

openapi: 3.0.1
info:
  title: Rest API
  version: "3"
servers:
- url: /rest
security:
- JwtAuth: []
- ApiKeyAuth: []
paths:
  /api/projects/{projectId}/depositFile:
    post:
      tags:
      - Deposit File
      summary: Deposit a file.
      operationId: depositFile
      parameters:
      - name: projectId
        in: path
        description: The ID of the project
        required: true
        schema:
          type: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/DepositFileDto'
      responses:
        "201":
          description: The file is deposited successfully.
          content:
            application/json: {}
components:
  schemas:
    DepositFileDto:
      required:
      - code
      - description
      - mainFile
      - parametersXmlFile
      type: object
      properties:
        code:
          maxLength: 255
          minLength: 1
          type: string
          description: The code of the file
        description:
          maxLength: 4000
          minLength: 1
          type: string
          description: The description of the file
        mainFile:
          type: string
          description: The main file.
          format: binary
        versionComment:
          type: string
          nullable: true

Desktop (please complete the following information):

  • OS: Windows 10
  • Python Version: 3.9.4
  • openapi-python-client version: 0.10.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions