swagger/springfox 使用杂记

参考资料:
  • http://heidloff.net/article/usage-of-swagger-2-0-in-spring-boot-applications-to-document-apis/
  • http://jakubstas.com/spring-jersey-swagger-create-documentation/#.WAcMhvl96Cp
  • http://springfox.github.io/springfox/


备忘几个常用的注解:
1、@ApiIgnore 用于屏蔽一些不想在文档中显示的接口
2、tag的使用
   有一些接口定义,写在不同的Controller中,但在文档中想显示在同一个分组中时。可以用tag来标记这个接口,如:
  
@ApiOperation(tags = { "IdentityInfo" }, value = "获取用户认证信息", httpMethod = "GET")

   在构造Docket Java Bean时,定义这些tag及描述,如:
   
.tags(new Tag("IdentityInfo", "用户在XX系统中的相关状态"))

3、获取swagger用的JSON文件的方式:
  http://localhost:8080/v2/api-docs
  获取该应用中的接口定义的JSON。可在swagger-editor中导入并重新编辑这些文件。
4、API页面不显示 basic-error-controller : Basic Error Controller
  在构造Docket时,使用
 
.paths(Predicates.not(PathSelectors.regex("/error"))).build()

猜你喜欢

转载自godjohnny.iteye.com/blog/2331577