OpenAPITools / OpenAPITools/openapi-generator

[BUG] Python client fails for camelCase multipart/form-data file binary property

Open
#9,927 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating the Python client code for the OAS YAML spec provided below, there's a mapping error in the generated code for the camelCase property inputFile of binary type:

The code is assigning params['file'][param_name] (param_name = 'input_file'), when it should be params['file'][base_name] (base_name = 'inputFile')

Generated code looks like:

                if (param_location == 'form' and
                        self.openapi_types[param_name] == (file_type,)):
                    params['file'][param_name] = [param_value]
                elif (param_location == 'form' and
                        self.openapi_types[param_name] == ([file_type],)):
                    # param_value is already a list
                    params['file'][param_name] = param_value

It should be:

                if (param_location == 'form' and
                        self.openapi_types[param_name] == (file_type,)):
                    params['file'][base_name] = [param_value]
                elif (param_location == 'form' and
                        self.openapi_types[param_name] == ([file_type],)):
                    # param_value is already a list
                    params['file'][base_name] = param_value
openapi-generator version

5.2.0

OpenAPI declaration file content or URL
minimal-api-spec.yaml (click expand to visualize them)

openapi: 3.0.1
info:
  title: My API
  version: 0.9.0

paths:
  /uploadFile:
    post:
      operationId: uploadFile
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                description:
                  type: string
                inputFile:
                  type: string
                  format: binary
              required:
                - description
                - inputFile
      responses:
        '201':
          description: Created

Generation Details
openapi-generator generate \
  --input-spec minimal-api-spec.yaml \
  --generator-name python \
  --package-name client \
  --output client
Steps to reproduce
  1. Generate the Python client code with the command above
  2. Verify the generated api_client.py has the wrong mapping for the 'file' params

Generated code looks like:

                if (param_location == 'form' and
                        self.openapi_types[param_name] == (file_type,)):
                    params['file'][param_name] = [param_value]
                elif (param_location == 'form' and
                        self.openapi_types[param_name] == ([file_type],)):
                    # param_value is already a list
                    params['file'][param_name] = param_value

It should be:

                if (param_location == 'form' and
                        self.openapi_types[param_name] == (file_type,)):
                    params['file'][base_name] = [param_value]
                elif (param_location == 'form' and
                        self.openapi_types[param_name] == ([file_type],)):
                    # param_value is already a list
                    params['file'][base_name] = param_value
Related issues/PRs

None

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with minimal-api-spec.yaml and run the documented openapi-generator command for the Python client. Inspect the generated api_client.py multipart file-parameter mapping for the camelCase inputFile property and compare it with the expected output in the issue; done means the generated mapping preserves inputFile for binary form data.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.