0

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?

  • It's not clear to me where the output is coming from and exactly what you want to prevent. Can you expand your question to include a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – Andy Wilkinson Jan 29 '21 at 13:43

1 Answers1

0

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.