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