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

body type mismatch

Đang mở
#963 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.

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
In the _get_kwargs generated method, the body is determined as File type (because the format in my swagger definition is binary), but it tries to access its .to_dict attribute (because body_type is considered as data due to the content type application/x-www-form-urlencoded), which does not exist because it is a file

OpenAPI Spec File

"content": {
    "application/x-www-form-urlencoded": {
        "schema": {
            "description": "do stuff",
            "type": "string",
            "format": "binary"
        }
    }
}

Desktop (please complete the following information):

  • OS: macOS 13.3.1
  • Python Version: 3.9.8
  • openapi-python-client version: 0.17.2

Additional context
In the macro, the arguments macro determine the argument type of body based on endpoint.bodies[0].prop.get_type_string(), whereas in the body_to_kwarg macro it determines it based on body.body_type, which is determined by the following:

        if simplified_content_type == "application/x-www-form-urlencoded":
            body_type = BodyType.DATA
        elif simplified_content_type == "multipart/form-data":
            body_type = BodyType.FILES
        elif simplified_content_type == "application/octet-stream":
            body_type = BodyType.CONTENT
        elif simplified_content_type == "application/json" or simplified_content_type.endswith("+json"):
            body_type = BodyType.JSON

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

Start with the generated _get_kwargs method and trace the arguments and body_to_kwarg macros, especially how endpoint.bodies[0].prop.get_type_string() differs from body.body_type. Review the application/x-www-form-urlencoded BodyType mapping and verify that a binary body no longer attempts to access .to_dict.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 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

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.