사용자 도구

사이트 도구


springframework:springfox

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
springframework:springfox [2018/07/24 13:40]
kwon37xi
springframework:springfox [2018/07/24 13:46]
kwon37xi [Spring MVC and swagger]
줄 6: 줄 6:
 > The Springfox suite of java libraries are all about automating the generation of machine and human readable specifications for JSON APIs written using the spring family of projects.  > The Springfox suite of java libraries are all about automating the generation of machine and human readable specifications for JSON APIs written using the spring family of projects. 
  
 +
 +===== Spring MVC and swagger =====
 +  * [[https://github.com/martypitt/swagger-springmvc|Swagger SpringMVC]]
 +  * [[https://github.com/adrianbk/swagger-springmvc-demo/tree/master/swagger-ui|Swagger-UI]]
 +  * Spring MVC Swagger 튜토리얼 시리즈
 +    * [[http://www.javacodegeeks.com/2014/10/spring-rest-api-with-swagger-creating-documentation.html|Spring Rest API with Swagger – Creating documentation Swagger 문서 생성]]
 +    * [[http://www.javacodegeeks.com/2014/11/spring-rest-api-with-swagger-exposing-documentation.html|Spring Rest API with Swagger – Exposing documentation]] Spring REST API를 웹 서비스로 볼 수 있게 해줌
 +  * <del>Spring MVC API 적용 Servlet의 "/"가 아닌 "/api/*" 형태로 매핑되면 Swagger 적용이 복잡해진다.</del> 최근 버전은 매우 간결해짐.<code java>
 +// /css/*, /js/* 등에 대한 핸들러 추가.
 +@Override
 +protected void addResourceHandlers(ResourceHandlerRegistry registry) {
 +  registry.addResourceHandler("css/**", "js/**", "lib/**", "images/**", "swagger-ui.js")
 +    .addResourceLocations(WEB_JAR_RESOURCE_LOCATION,
 +        WEB_JAR_RESOURCE_LOCATION + "css/",
 +        WEB_JAR_RESOURCE_LOCATION + "js/",
 +        WEB_JAR_RESOURCE_LOCATION + "lib/",
 +        WEB_JAR_RESOURCE_LOCATION + "images/")
 +    .setCachePeriod(0);
 +  super.addResourceHandlers(registry);
 +}
 +
 +@ApiIgnore
 +@Controller
 +public class SwaggerController {
 +  @Autowired
 +    private ResourceLoader resourceLoader;
 +
 +  @RequestMapping("/swagger")
 +    public void swagger(HttpServletResponse response) throws IOException {
 +      final Resource swaggerHtmlResource =
 +        resourceLoader.getResource("classpath:/META-INF/resources/sdoc.jsp");
 +
 +      final String swaggerHtmlContents =
 +        CoupangIOUtils.toString(swaggerHtmlResource.getInputStream(), "UTF-8");
 +      final String refinedHtml = swaggerHtmlContents
 +        .replaceAll("http://swagger.wordnik.com", "/api/swagger");
 +
 +      response.setContentType("text/html; charset=UTF-8");
 +      final PrintWriter writer = response.getWriter();
 +      writer.write(refinedHtml);
 +      writer.close();
 +    }
 +}
 +</code>
  
 ===== 참조 ===== ===== 참조 =====
   * [[http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api|Setting Up Swagger 2 with a Spring REST API ]] [[http://springboot.tistory.com/24|Spring REST API에 Swagger 2 설정하기]]   * [[http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api|Setting Up Swagger 2 with a Spring REST API ]] [[http://springboot.tistory.com/24|Spring REST API에 Swagger 2 설정하기]]
springframework/springfox.txt · 마지막으로 수정됨: 2020/08/26 10:32 저자 kwon37xi