[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
- Generate the Python client code with the command above
- 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