OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python][Generator] Setting package name with dash propagates to generated code without replacing dash with underscore

Open
#17,315 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Try to generate any python schema with --package-name <some name with dash>, and you should see the issue. The detrimental side of this issue is that dashes are not valid in module imports:

import my-api-client

This is bad. We want:

import my_api_client
openapi-generator version

openapi-generator-cli 7.1.0
commit : unknown
built : -999999999-01-01T00:00:00+18:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech

OpenAPI declaration file content or url

Try with this, note the problem is schema independent:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: service1
  description: Service description
  contact:
    name: Maintainer name
    email: Maintainer email
servers:
  - url: service1.company.com
paths:
  /path/to/api:
    get:
      summary: sample handler
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Resp'
components:
  schemas:
    Resp:
      type: object
      properties:
        prop1:
          type: string
        prop2:
          type: string
      required:
        - prop2
Generation Details
openapi-generator generate \
        --generator-name python \
        --input-spec openapi.yaml \
        --package-name {{ name with underscore!! }} \
        --additional-properties=packageVersion=$(poetry version -s)

Current workaround, run this after generation:

sed -i 's/name = {{ name with underscore!! }}/name = {{ name with dash!! }}/' {{ api_gen_dir }}/pyproject.toml

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 problem with the minimal OpenAPI YAML and the supplied Python generator command using a dashed package name. Inspect the generated Python imports and package files, then verify that generated module references use underscores while the package metadata remains correct.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.