OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Python] Misplaced __init__.py in client code when period is specified in package name

Open
#2,722 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

a) Generating a python client with both --model-package and --api-package parameters containing a '.' creates the api and models init.py file in the wrong directory.
Options --model-package pkg.models and --api-package pkg.api generate the directories openapi_client/pkg.models and openapi_client/pkg.api, in addition to openapi_client/pkg/models and openapi_client/pkg/api.

b) The init.py for the api contains wrong import lines, while the "model" one is correct.

--- openapi_client/pkg.models/init.py:

import models into model package

from openapi_client.pkg.models.error import Error
from openapi_client.pkg.models.pet import Pet

--- openapi_client/pkg.api/init.py ("openapi_client." missing form package name):

import apis into api package

from pkg.api.pets_api import PetsApi

openapi-generator version

Confirmed with v4.0.0-beta3

OpenAPI declaration file content or url

Using standard petstore.json

Command line used for generation

openapi-generator generate -g python -i petstore.json -o output --model-package pkg.models --api-package pkg.api

Steps to reproduce

Run the command above on the standard petstore.json spec file

Related issues/PRs

a) PR #2508 fixes a similar issue in the server code.

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

Run the provided openapi-generator command with petstore.json, --model-package pkg.models, and --api-package pkg.api, then inspect the generated openapi_client/pkg.models and openapi_client/pkg.api paths. Compare their init.py locations and import lines with the expected package structure, and review PR #2508 for the related server-side fix; done means no extra dotted-directory packages and correct imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.