SpringBoot/OpenAPI - Web layer testing with api-first approach

Viewed 13

I'm trying to find out correct approach of testing openAPI specification that is written first and used to generate apis + models.

I found several solutions (workarounds) and would like to hear qualified opinions on that + maybe something else.

  1. WebTestMvc annotation + Import for the handler that implements Delegate interface (without import I get 501 as it fallbacks to default openAPI impl)

     @WebMvcTest(OrderApiController.class)
     @Import(OrderHandler.class)
     class OrderHandlerTest {
    
         @Autowired
         private MockMvc mockMvc;
         @Test
         void createOrder() throws Exception {
             mockMvc.perform(post("/orders")
                     .contentType(MediaType.APPLICATION_JSON)
                     .content("{}"))
                     .andExpect(status().isOk());
         }
    
  2. Exclude controllers from openAPI generation, disable delegates and just implement Api interface with own controller - not sure this is good approach as this way we are losing information about basePath in openApi spec.

0 Answers
Related