Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9927
Closed
Open
Issue created Jul 10, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: alejogun

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
Assignee
Assign to
Time tracking