Spring REST Docs + RequestBody + Prevent deep-level documentation of fields

491 views Asked by At

i have problems with Spring REST Docs and preventing deep-level documentation of fields within a request body:

@Transactional
    @RequestMapping(path = "/edit", method = RequestMethod.POST)
    public ResponseEntity<Void> edit(
            @RequestParam("id") Long id,
            @RequestBody TreeItemResource root)

and the test for documentation:

@Test
    public void edit() throws Exception {
        
        //...
        
        this.getMockMvc(this.controller).perform(post("/edit"))
                .andDo(document("root",
                        requestFields(
                                subsectionWithPath("childs"))));
        
    }

This test needs much time and the output ist the following:

root.childs[].childs[].childs[].childs[].childs[].childs[].path

How can i prevent this?

1

There are 1 answers

0
alex_steward On BEST ANSWER

I found a solution!

The annotation @RestdocsNotExpanded is for this purpose. You have to annotate fields of your DTO that should not be expanded inside your REST Api documentation.