openapi-generators / openapi-generators/openapi-python-client

TypeError when model default value is a list

Đang mở
#721 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

🐞bug
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
When generating models for an API where a default argument is a list of enums, a TypeError is raised on this line:

return f"{prop.class_info.name}.{inverse_values[default]}"

A possible fix could be to explicitly check for this case. Below is a proposed fix, but I'm not familiar enough with the codebase to know whether this is a correct fix. However, I was able to parse the API docs correctly with this fix in place:

if type(default) is list:
    return [f"prop.class_info.name.inverse_values[d]" for d in default]
else:
    return f"{prop.class_info.name}.{inverse_values[default]}"

To Reproduce
Steps to reproduce the behavior:

  1. Run openapi-python-client generate --url https://sand-docs.ilevelsolutions.eu/openapi.yaml
  2. See error

Expected behavior
The API docs should be able to be parsed

OpenAPI Spec File
https://sand-docs.ilevelsolutions.eu/openapi.yaml

Desktop (please complete the following information):

  • OS: macOS 13.1
  • Python Version: 3.10
  • openapi-python-client version: 0.13.1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong openapi_python_client/parser/properties/init.py, khoảng dòng 463, và tái hiện lỗi bằng openapi-python-client generate --url https://sand-docs.ilevelsolutions.eu/openapi.yaml. Theo dõi cách các giá trị mặc định của enum có giá trị dạng danh sách được biểu diễn và kiểm tra các bài kiểm thử parser liên quan. Công việc được xem là hoàn tất khi specification được tạo thành công mà không có TypeError và hành vi hiện tại vẫn được giữ nguyê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ệ
openapi, 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
Đặc tả rõ ràng
Mức phù hợp với người mới
65/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.