OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python] form-data parameter generated in snake_case, but actually passed in camelCase

Open
#4,796 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When passing a file to a 'form/data' field in the generated client, the actual file payload is None.

We have a JSON file where we declared the 'file' parameter with a camelCase name (upgradePackage). When generating the client from this JSON file, we can see that the name is converted to snake_case in our generated controller, and the argument is now called 'upgrade_package'.

However, this argument is actually empty. See JSON below.

So, our controller is generated with the following function signature:

def upgrade(upgrade_package=None):
but, this parameter is not populated at all, i.e.
print(upgrade_package) returns 'None'.

But, we can access the actual file by:
print(request.files.get('upgradePackage')) <-- this prints the file object reference.

We've also validated this behavior from Postman. If we setup a post to our service with form/data, and call the passed file parameter 'upgrade_package' - it works. Calling the parameter 'upgradePackge' does not work.

openapi-generator version

Tried 4.0.0 and 4.2.2.

OpenAPI declaration file content or url
"paths": {
    "/maintenance/upgrade": {
      "post": {
        "responses": {
          "202": {
            "description": "upgrade request accepted",
            "schema": {
              "type": "string"
            }
          },
        "summary": "Upgrade",
        "operationId": "Upgrade",
        "tags": [
          "Upgrade"
        ],
        "produces": [
          "application/json"
        ],
        "description": "Upload an upgrade package",
        "consumes": [
          "multipart/form-data"
        ],
        "parameters": [
          {
            "in": "formData",
            "name": "upgradePackage",
            "type": "file"
          }
        ]
      }
    }
  }
Command line used for generation

java -jar -Dlog.level=warn -DapiTests=false -DmodelTests=false openapi-generator-cli-4.0.0.jar generate -i <swagger_file.json> -g python-flask -o <output_dir> -t templates/python --package-name

Steps to reproduce

Generate python flash server from a JSON which is set to accept 'form/data' and used a camelCase naming schema for its file name.

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 the python-flask generator and its templates/python form-data handling, then reproduce the issue using the supplied OpenAPI formData declaration and generation command. Verify how the declared camelCase file name is mapped into the generated handler. Done means the generated handler receives the uploaded file while preserving the declared request field name.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.