OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python] Models not generated for lowercase schema names, causing ImportError

Open
#22,661 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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?
  • Have you tested with the latest master?
  • Have you searched for related issues/PRs?

Description

When schema components are defined with lowercase names (e.g., item, itemList), the Python generator does not generate model files, but the generated API files still try to import these models, causing ModuleNotFoundError at runtime.

openapi-generator version

7.10.0 (via openapi-generator-cli)

OpenAPI declaration file content or url

Minimal reproduction (fails):

openapi: 3.0.0
info:
  title: Minimal Repro
  version: 1.0.0
paths:
  /items:
    get:
      operationId: getItems
      responses:
        '200':
          description: List of items
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/itemList'
  /items/{id}:
    get:
      operationId: getItem
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Single item
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/item'
components:
  schemas:
    item:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
    itemList:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/item'

Same spec with PascalCase names (works):

Replace item with Item and itemList with ItemList - models are generated correctly.

Generation Details

openapi-generator-cli generate \
  --generator-name python \
  --input-spec spec.yaml \
  --output output \
  --additional-properties=packageName=repro,library=httpx,generateSourceCodeOnly=true

Steps to reproduce

  1. Save the minimal spec above as spec.yaml
  2. Run the generation command
  3. Observe that models/ directory contains only __init__.py (no model files)
  4. Observe that api/default_api.py contains:
    from repro.models.item import Item
    from repro.models.item_list import ItemList
    
  5. Try to import: python -c "from repro.api.default_api import DefaultApi"

Expected behavior

Model files should be generated for schemas regardless of casing:

  • models/item.py with class Item
  • models/item_list.py with class ItemList

Actual behavior

  • No model files are generated
  • API files import non-existent models
  • Runtime error: ModuleNotFoundError: No module named 'repro.models.item'

Related issues/PRs

None found.

Suggest a fix

The generator should normalize schema names and generate model files regardless of the original casing in the OpenAPI spec.

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 by running the provided openapi-generator-cli command with the lowercase-schema spec and inspect the generated models/ and api/default_api.py paths. Trace why models/item.py and models/item_list.py are omitted while imports are emitted. Done means the Python generator creates both model files and the shown import command succeeds for lowercase and PascalCase schema names.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.