openapi-generators / openapi-generators/openapi-python-client
Model import shadows HTTP `Client` import when a schema is named `Client`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 2k
- Forks
- 293
- Ø Merge
- 34 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
Describe the bug
When an OpenAPI spec contains a schema named Client, the generated endpoint modules import both the HTTP Client class and the Client model class under the same name. The model import silently shadows the HTTP client import, making Client in type annotations refer to the wrong class.
endpoint_module.py.jinja unconditionally emits:
from ...client import AuthenticatedClient, Client
Then endpoint.relative_imports adds model imports. When a model is also named Client, the result is:
from ...client import AuthenticatedClient, Client # HTTP client
from ...models.client import Client # model — shadows the line above
This causes Client in _parse_response and _build_response type annotations to resolve to the model instead of the HTTP client class.
OpenAPI Spec File
Minimal reproduction:
openapi: "3.0.3"
info:
title: Minimal repro
version: "1.0"
paths:
/api/clients/{id}:
patch:
operationId: update_client
tags:
- client
parameters:
- name: id
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Client"
components:
schemas:
Client:
type: object
properties:
name:
type: string
In the generated api/client/update_client.py, line 6 imports Client from ...client and line 10 re-imports Client from ...models.client, shadowing it.
Desktop (please complete the following information):
- OS: macOS 15 (ARM64)
- Python Version: 3.13
- openapi-python-client version: 0.27.1 (also verified on 0.28.3)
Additional context
We worked around this by using custom templates.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit endpoint_module.py.jinja und der Logik hinter endpoint.relative_imports. Generieren Sie anschließend die minimale OpenAPI-Spezifikation aus dem Issue. Überprüfen Sie die Imports in der generierten api/client/update_client.py sowie die Annotationen von _parse_response und _build_response. Die Aufgabe ist abgeschlossen, wenn ein Schema namens Client nicht mehr dazu führt, dass die Referenz auf HTTP Client überschattet wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 70/100