Improve beneathPath to work with multiple nested arrays

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

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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
api, documentation

Hướng nghiên cứu

Start by tracing the beneathPath() entry point with the nested roles and more payload shown in the issue, comparing beneathPath("roles[].more") with the single-array case. The change is done when the nested array can be documented with fieldWithPath("id") and generated paths no longer begin with [].

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

Mô tả

type: enhancement

In beneathPath(), paths with an array work now, thanks to #473 and 9e1ba8a. But I'm still having a problem with arrays when there are two levels of arrays in the payload.
Consider the payload:

{
  "roles": [
    {
      "key": "1",
      "name": "one",
      "more": [
        {
          "id": 1
        }
      ]
    },
    {
      "key": "1",
      "name": "one",
      "more": []
    }
  ]
}

And I document it like so:

document(snippetName,
        responseFields(
            // beneathPath understands that roles is an array and does the right thing
            beneathPath("roles").withSubsectionId("roles"), 
            fieldWithPath("key").description("key"),
            fieldWithPath("name").description("name"),
            subsectionWithPath("more").description("array")));

This will give me the fields of roles with a description of the more property. To then document the object within the more array, I do a separate snippet:

document(snippetName,
        responseFields(
            // now beneathPath doesn't deal with 'roles' here like it does above
            beneathPath("roles[].more").withSubsectionId("more"), 
            fieldWithPath("[].id").description("id")));

The issue here is that at this point, the second array, the problem is the same as #473, you get a snippet with [] in front of the field path, which is functional, but not great from a documentation standpoint, which is the whole point.

To make this work like the single array, I'd expect maybe beneathPath("roles.more") to work with fieldWithPath("id"), giving me a table with Paths like id in this case.

Ngôn ngữ chính
Java
Star
1.2k
Fork
733
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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

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 spring-projects/spring-restdocs

Tất cả issue của spring-projects/spring-restdocs

Issue tương tự

Thêm issue về Java

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.