Rest 弹簧座文件-未记录的零件:

Rest 弹簧座文件-未记录的零件:,rest,spring-boot,spring-mvc,spring-rest,spring-restdocs,Rest,Spring Boot,Spring Mvc,Spring Rest,Spring Restdocs,我有一个springBoot 2.1.9.RELEASE应用程序,它使用SpringREST文档 我有这个有效载荷 { "hostel" : [ { "bookingHostelIdentifier" : { "internalMasterIdentifier" : { "id" : "987654321" } } }, { "bookingHostelIdentifier" : { "customerIdent

我有一个springBoot 2.1.9.RELEASE应用程序,它使用SpringREST文档

我有这个有效载荷

{
  "hostel" : [ {
    "bookingHostelIdentifier" : {
      "internalMasterIdentifier" : {
        "id" : "987654321"
      }
    }
  }, {
    "bookingHostelIdentifier" : {
      "customerIdentifier" : {
        "id" : "23456789"
      }
    }
  }, {
    "bookingHostelIdentifier" : {
      "internalMasterIdentifier" : {
        "id" : "87654321"
      }
    }
  } ]
}
我是这样记录的

fieldWithPath("hostel[]").description("The list of hostels"),
fieldWithPath("hostel[].name").description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier").description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier.internalMasterIdentifier.id").description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier.customerIdentifier.id").description("The list of hostels")
但我有个例外

org.springframework.restdocs.snippet.SnippetException: 
Fields with the following paths were not found in the payload: 
[hostel[].bookingHostelIdentifier.internalMasterIdentifier.id, hostel[].bookingHostelIdentifier.customerIdentifier.id]
由于internalMasterIdentifier和customerIdentifier字段并不总是出现在BookingHostIdentifier中,因此您应该将这些字段或嵌套在它们下面的id字段标记为可选字段

fieldWithPath("hostel[].bookingHostelIdentifier.internalMasterIdentifier.id").optional().description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier.customerIdentifier.id").optional().description("The list of hostels")

如果将internalMasterIdentifier和添加到每个实体中会怎么样?在有效载荷中,我不在乎它是否有效,只想知道它是否有效