An unexpected model is generated when server returns dictionary

Offen
#610 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
38/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
fastapi, python
Bereich
api, tooling

Rechercherichtung

Beginne damit, die FastAPI-Route get_clipon_metadata_by_clip_name_list mit response_model=Dict[str, CliponMetadata] zu reproduzieren, und untersuche das generierte Antwortmodell sowie die geparsten additional_properties. Vergleiche dies mit dem Antwortfall List[CliponMetadata]. Als abgeschlossen gilt die Aufgabe, wenn Antworten vom Typ dictionary das erwartete CliponMetadata-Modell ohne das unerwünschte Wrapper-Modell mit langem Namen generieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

🐞bug

Describe the bug
I have a web API implementer with fastAPI. I have a function that make a POST request to the server I work with. This function returns dictionary that maps string to an object called "Clipon".

@router.get("/clipon/{version}", tags=["clipon"], status_code=status.HTTP_200_OK, response_model=Dict[str, CliponMetadata])
async def get_clipon_metadata_by_clip_name_list(version: str, clip_list: List[str]):
    try:
        res = await db_client.get_by_clip_name_list(clip_list=clip_list, version=version)
    except AssertionError as ex:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(ex))
    return {clip.clip_name: clip for clip in res}

When generating the models with openapi-python-client, what is generated is a model names "clipon_metadata" (as expected), and also another unexpected model with a long name:
image
It's full name is "GetCliponMetadataByClipNameListCliponVersionPostResponseGetCliponMetadataByClipNameListCliponVersionPost".

I don't understand why this model is created. For example, when I change this function to return List[CliponMetadata], only the "clipon_metadata" model is created.

In this behavior, when the client make this POST request, what it gets is A response object (also generated automatically), which in it's "parsed" attribute contains the unwanted object, and the "additional_properties" attribute of "parsed" holds the desired dictionary:

image

Expected behavior
I'd like that only the "clipon"metadata" model will be generated.

Desktop:

  • OS: Linux (Ubuntu)
  • Python Version: 3.9.1
  • openapi-python-client version: 0.11.1
Vorherrschende Sprache
Python
Sterne
2k
Forks
293
Ø Merge
34 Min.
Gemergte PRs (30 T.)
1

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus openapi-generators/openapi-python-client

Alle Issues in openapi-generators/openapi-python-client

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.