openapi-generators / openapi-generators/openapi-python-client
An unexpected model is generated when server returns dictionary
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 293
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the FastAPI route get_clipon_metadata_by_clip_name_list with response_model=Dict[str, CliponMetadata] and inspect the generated response model and parsed additional_properties. Compare this with the List[CliponMetadata] response case. Done means dictionary responses generate the expected CliponMetadata model without the unwanted long-named wrapper model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100