사용자 도구

사이트 도구


programming:documentation:swagger

Swagger

ReDoc

RapiDoc

Swagger2MarkUp

// Spring / Swagger 에서 swagger.json 을 파일로 뽑아내는 예제
 
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@AutoConfigureRestDocs(outputDir = "build/asciidoc/snippets")
@SpringBootTest(classes = {Application.class, SwaggerConfig.class})
@AutoConfigureMockMvc
public class Swagger2MarkupTest {
 
    private static final Logger LOG = LoggerFactory.getLogger(Swagger2MarkupTest.class);
 
 
    @Autowired
    private MockMvc mockMvc;
 
...
 
    @Test
    public void createSpringfoxSwaggerJson() throws Exception {
        //String designFirstSwaggerLocation = Swagger2MarkupTest.class.getResource("/swagger.yaml").getPath();
 
        String outputDir = System.getProperty("io.springfox.staticdocs.outputDir");
        MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs")
                .accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andReturn();
 
        MockHttpServletResponse response = mvcResult.getResponse();
        String swaggerJson = response.getContentAsString();
        Files.createDirectories(Paths.get(outputDir));
        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){
            writer.write(swaggerJson);
        }
    }
...
}

기타

programming/documentation/swagger.txt · 마지막으로 수정됨: 2024/07/31 14:18 저자 kwon37xi