Skip to content

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

@poodle64

Description

@poodle64

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions