openapi-generators / openapi-generators/openapi-python-client
An unexpected model is generated when server returns dictionary
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 2k
- Fork
- 293
- Merge trung bình
- 34 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện route FastAPI get_clipon_metadata_by_clip_name_list với response_model=Dict[str, CliponMetadata] và kiểm tra response model được tạo ra cùng các additional_properties đã được phân tích. So sánh trường hợp này với trường hợp response List[CliponMetadata]. Hoàn thành khi các response dạng dictionary tạo ra model CliponMetadata như mong đợi mà không có wrapper model có tên dài không mong muốn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- fastapi, python
- Lĩnh vực
- api, tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100