Multiple body-types in an endpoint with same model (referenced via `$ref`) results in ambiguity in generated code
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia tracciando il modo in cui il generatore gestisce le voci content di OpenAPI requestBody e produce la funzione generata _get_kwargs. Riproduci il problema con lo snippet JSON fornito, quindi aggiungi la copertura per application/json e multipart/form-data; il lavoro sarà completato quando il client generato selezionerà la gestione corretta del body senza condizioni identiche ambigue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
| Python Version | OpenAPI Client Generator Version |
|---|---|
| 3.11.6 | 0.18.0 |
Actual Behavior
When an endpoint has multiple body types, each referencing the same model (via a $ref key), the generator generates the same class name for each body types, which results then in the following generated code:
def _get_kwargs(
# ...
):
# ...
if isinstance(body, WritableJournalEntryRequest):
_json_body = body.to_dict()
_kwargs["json"] = _json_body
headers["Content-Type"] = "application/json"
if isinstance(body, WritableJournalEntryRequest):
_files_body = body.to_multipart()
_kwargs["files"] = _files_body
headers["Content-Type"] = "multipart/form-data"
# ...
As you can see, both if-statement's conditions will resolve to True, therefore only the last body type will be used.
Desired Behavior
The body-type should be part of the generated class name to avoid such ambiguities.
Or an if/elseif/else should be used in the template (which would result in the first one being applied ONLY).
OpenAPI Spec File
The OpenAPI spec is from Netbox, but here is the relevant snippet:
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WritableJournalEntryRequest"
}
},
"multipart/form-data": {
"schema": {
"$ref": "#/components/schemas/WritableJournalEntryRequest"
}
}
},
"required": true
},
- Lingua principale
- Python
- Stelle
- 2k
- Fork
- 293
- Merge medio
- 34m
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openapi-generators/openapi-python-client
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
openapi-generators/openapi-python-client#1451 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
openapi-generators/openapi-python-client#1435 · 1 commento ·
Tutte le issue di openapi-generators/openapi-python-client
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
zostera/django-bootstrap4#894 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3276 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·