InvalidResponsePayload instead of Option::None for nullable api endpoint.

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu từ entry point from_response được sinh ra và hiển thị trong báo cáo, rồi tái hiện response của nullable endpoint với body rỗng. Kiểm tra việc phân tích các response xung quanh và độ bao phủ của test, sau đó thêm một trường hợp hồi quy để phân biệt body rỗng với payload không rỗng không hợp lệ và xác minh hành vi Option dự kiến.

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

Mô tả

I have an API endpoint that may return no response or some type Inode like this:

 "/fs/resolve/{path}": {
      "get": {
        "operationId": "resolvePath",
        "responses": {
          "2XX": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Inode"
                    }
                  ],
                  "nullable": true
                }
              }
            }
          }
        },
        "tags": [
          "Filesystem"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },

typify correctly generates an Option type but if the API returns an empty body i get an InvalidResponsePayload error.
I tracked this down to serde being unable to parse an empty byte array b"" to an Option None here:

    pub async fn from_response<E>(response: reqwest::Response) -> Result<Self, Error<E>> {
        let status = response.status();
        let headers = response.headers().clone();
        let full = response.bytes().await.map_err(Error::ResponseBodyError)?;
        let inner =
            serde_json::from_slice(&full).map_err(|e| Error::InvalidResponsePayload(full, e))?;

        Ok(Self {
            inner,
            status,
            headers,
        })
    }

Can a case for this be added?
I already tried adding a specific 204 Response to the schema, but this fails with assertion failed: response_types.len() <= 1

Ngôn ngữ chính
Rust
Star
1k
Fork
142
Merge trung bình
19 giờ 13 phút
Pull request đã merge (30 ngày)
16

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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.

Issue khác của oxidecomputer/progenitor

Tất cả issue của oxidecomputer/progenitor

Issue tương tự

Thêm issue về Rust

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.