문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
programming:documentation:swagger [2018/07/24 13:44] kwon37xi [SpringBoot] |
programming:documentation:swagger [2024/07/31 14:18] (현재) kwon37xi |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Swagger ====== | ====== Swagger ====== | ||
* http:// | * http:// | ||
+ | * [[programming: | ||
+ | * -> [[programming: | ||
+ | * [[springframework: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
- | ===== Spring MVC and swagger | + | ===== ReDoc ===== |
- | * [[https:// | + | * [[https:// |
- | * [[https:// | + | * [[https://webhookrelay.com/blog/2018/11/05/openapi-redoc-tutorial/|Documenting your API with OpenAPI (Swagger) and Redoc — Web Relay]] |
- | * Spring MVC Swagger 튜토리얼 시리즈 | + | * 페이지 내 검색과 더 유려한 UI를 제공해줌. |
- | * [[http:// | + | |
- | * [[http://www.javacodegeeks.com/2014/11/spring-rest-api-with-swagger-exposing-documentation.html|Spring Rest API with Swagger | + | |
- | * Spring MVC API 적용 Servlet의 "/" | + | |
- | // /css/*, /js/* 등에 대한 핸들러 추가. | + | |
- | @Override | + | |
- | protected void addResourceHandlers(ResourceHandlerRegistry registry) { | + | |
- | registry.addResourceHandler(" | + | |
- | .addResourceLocations(WEB_JAR_RESOURCE_LOCATION, | + | |
- | WEB_JAR_RESOURCE_LOCATION + " | + | |
- | WEB_JAR_RESOURCE_LOCATION + " | + | |
- | WEB_JAR_RESOURCE_LOCATION + " | + | |
- | WEB_JAR_RESOURCE_LOCATION + " | + | |
- | .setCachePeriod(0); | + | |
- | super.addResourceHandlers(registry); | + | |
- | } | + | |
- | @ApiIgnore | + | ===== RapiDoc ===== |
- | @Controller | + | |
- | public class SwaggerController { | + | |
- | | + | |
- | private ResourceLoader resourceLoader; | + | |
- | @RequestMapping("/ | ||
- | public void swagger(HttpServletResponse response) throws IOException { | ||
- | final Resource swaggerHtmlResource = | ||
- | resourceLoader.getResource(" | ||
- | final String swaggerHtmlContents | + | ===== Swagger2MarkUp ===== |
- | | + | * [[https:// |
- | final String refinedHtml = swaggerHtmlContents | + | * [[https:// |
- | | + | * [[https://github.com/ |
+ | * [[https:// | ||
+ | <code java> | ||
+ | // Spring / Swagger 에서 | ||
- | response.setContentType("text/html; charset=UTF-8"); | + | @WebAppConfiguration |
- | final PrintWriter writer | + | @RunWith(SpringJUnit4ClassRunner.class) |
- | | + | @AutoConfigureRestDocs(outputDir = "build/asciidoc/ |
- | writer.close(); | + | @SpringBootTest(classes = {Application.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 | ||
+ | |||
+ | String outputDir = System.getProperty(" | ||
+ | MvcResult mvcResult = this.mockMvc.perform(get("/ | ||
+ | .accept(MediaType.APPLICATION_JSON)) | ||
+ | .andExpect(status().isOk()) | ||
+ | .andReturn(); | ||
+ | |||
+ | MockHttpServletResponse response = mvcResult.getResponse(); | ||
+ | String swaggerJson | ||
+ | Files.createDirectories(Paths.get(outputDir)); | ||
+ | try (BufferedWriter | ||
+ | writer.write(swaggerJson); | ||
+ | } | ||
} | } | ||
+ | ... | ||
} | } | ||
</ | </ | ||
- | + | ===== 기타 ===== | |
+ | * https:// | ||
+ | * [[https:// |