Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :)

like image 789
mibrahim.iti Avatar asked Dec 18 '22 02:12

mibrahim.iti


1 Answers

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.

like image 167
Andy Wilkinson Avatar answered Dec 28 '22 09:12

Andy Wilkinson