openapi-python-client
openapi-python-client copied to clipboard
An unexpected model is generated when server returns dictionary
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:
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:
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