OpenAPITools / OpenAPITools/openapi-generator

[BUG] Python generator with "--api-package" does not create "__init__.py" files in generated directories

Open
#19,870 2 comments 0 reactions 1 assignee View on GitHub

@kay-schecker is already working on this.

Since Oct 14, 2024.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

🐛 Bug Report:

Describe the bug

When using openapi-generator-cli version 7.9.0 to generate Python client code with the --api-package option, the generator does not create an __init__.py file in the specified package directory. This causes the generated sub-packages to not be recognized as Python modules, leading to issues during package installation and usage.

Specifically, the command used:

openapi-generator-cli generate -i /input/openapi.yaml -g python --api-package org.my.test.api -o /output --package-name openapi_client

creates the correct directory structure (openapi_client/org/my/test/api/), but none of the directories (org, my,test, api) contain the necessary __init__.py file.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Use openapi-generator-cli version 7.9.0 to generate Python code with the following command:
openapi-generator-cli generate -i /input/openapi.yaml -g python --api-package org.my.test.api -o /output --package-name openapi_client
  1. Navigate to the output directory (/output/openapi_client).
  2. Check the directory structure org/my/test/api/
  3. Observe that the __init__.py file is missing in all of these directories
Expected behavior

Each directory generated under --api-package should contain an __init__.py file, so that it is recognized as a Python package. This would allow seamless usage and installation of the generated client without requiring manual intervention to add these files.

Operation System (please complete the following information):
  • I'm working with docker version: openapitools/openapi-generator-cli:v7.9.0
Package System (please complete the following information):
  • openapi-generator-cli Version: 7.9.0
Additional context

The lack of __init__.py files in the generated package structure requires manual intervention, which is cumbersome and makes the automated generation process incomplete. It would be helpful if the generator automatically created these files to ensure all directories are treated as Python packages. This issue impacts the usability of generated clients, especially when --api-package is used to specify custom package paths.

Please let me know if you need more information or have any suggestions for resolving this issue.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.