0

我已经创建了一个端点并为它实现了一个 rest-doc。https://scacap.github.io/spring-auto-restdocs/

@PostMapping("post-item")
public ResponseEntity<?> postItem(@RequestBody ItemDto dto)
{
   ...
} 

class ItemDto {
    String value;
    
    @JsonIgnore
    public String getOther() {
       ...
    }
}

然后我为它创建了一个模拟测试方法:

@BeforeEach
public void setUp(WebApplicationContext webApplicationContext,
                  RestDocumentationContextProvider restDocumentation,
                  @Autowired ObjectMapper objectMapper,
                  @Value("${documentation.test.domain}") String domainName)
{
    this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
            .alwaysDo(JacksonResultHandlers.prepareJackson(objectMapper))
            .apply(documentationConfiguration(restDocumentation)
                    .uris()
                    .withScheme("http")
                    .withHost(domainName)
                    .withPort(8080)
                    .and().snippets()...
}



    @Test
    public void postItem() throws Exception
    {
        this.mockMvc.perform(post("/post-item")
                .contentType(MediaType.APPLICATION_JSON)
                .content(gson.toJson(new ItemDto("value"))))
                .andExpect(status().isOk());
    }

因此,spring rest-docs 生成带有 @JsonIgnore 字段的文档。

Request fields

value
other

有没有办法从 spring rest-docs 中忽略这个 @JsonIgnore 字段?

4

0 回答 0