我如何使用 spring 文档记录 java.util.Map

How could i document java.util.Map using spring docs

假设我有下一个 class

public class MyDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    private Map<String, String> names;

    // public Getters and Setters
}

当我使用下一个代码来记录它时 Spring

private static FieldDescriptor[] myDTOFields() {
  return new FieldDescriptor[] { 
    fieldWithPath("id").description("id description"),
    fieldWithPath("names").description("Names description") };
}

它不起作用,我得到一个错误。

org.springframework.restdocs.snippet.SnippetException: The following parts of the payload were not documented:

{
  "names" : {
    "en" : "test"
  }
}

那么我如何使用 spring 文档记录 java.util.Map?

谢谢:)

作为 described in the documentation,您可以为此使用 PayloadDocumentation.subsectionWithPath(“names”)。这意味着 REST Docs 认为 names 及其包含的所有内容都已记录。