OpenAPITools / OpenAPITools/openapi-generator

[BUG] Description

Open
#3,870 2 comments 1 reaction 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 trying to generate the code for a file upload endpoint in aiohttp (python), it generates a "file" type for the binary string.

openapi-generator version

4.1.1

OpenAPI declaration file content or url
/upload:
    post:
      tags:
        - file
      summary: Upload file
      description: File upload
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Response'
        '400':
          description: Bad data
      requestBody:
          content:
            multipart/form-data:
              schema:
                type: object
                properties:
                  fileId:
                    type: integer
                  userId:
                    type: integer
                  fileName:
                    type: string
                    format: binary
Command line used for generation

java -jar $jarfile generate -i spec.yaml -g python-aiohttp --package-name test_project -o ./

Steps to reproduce

Run the generation code with the endpoint above. It produces the following model, where the "file" type is undefined:

class InlineObject(Model):
    """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).

    Do not edit the class manually.
    """

    def __init__(self, file_id: int=None, user_id: int=None, file_name: file=None):
        """InlineObject - a model defined in OpenAPI

        :param file_id: The file_id of this InlineObject.
        :param user_id: The user_id of this InlineObject.
        :param file_name: The file_name of this InlineObject.
        """
        self.openapi_types = {
            'file_id': int,
            'user_id': int,
            'file_name': file
        }
Related issues/PRs
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

Reproduce the issue with the supplied OpenAPI YAML and the java -jar ... generate -g python-aiohttp command, then trace the python-aiohttp generator's type mapping for the string schema with binary format. Done means the generated InlineObject uses a defined binary-file type instead of file, while the integer fields remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.