4

Imagine I have next class

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

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

    // public Getters and Setters
}

When I use the next code to document it with Spring

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

It doesn't work and I get an error.

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

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

So how could I document java.util.Map with spring docs?

Thanks :)

Mathias Dpunkt
  • 11,594
  • 4
  • 45
  • 70
mibrahim.iti
  • 1,928
  • 5
  • 22
  • 50

1 Answers1

11

As described in the documentation, you could use PayloadDocumentation.subsectionWithPath(“names”) for this. It will mean that REST Docs considers names and everything that it contains as having been documented.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242