├── .gitignore ├── LICENSE ├── README.md ├── doc └── img │ ├── 1.png │ ├── 2.png │ ├── 2_1.png │ ├── 2_2.png │ ├── 2_3.png │ ├── 2_4.png │ ├── 3.png │ └── 4.png ├── pom.xml ├── swagger-spring-boot-actuator ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── battcn │ │ └── boot │ │ └── swagger │ │ └── actuate │ │ ├── autoconfigure │ │ └── SwaggerEndpointsAutoConfiguration.java │ │ └── endpoint │ │ └── SwaggerEndpoint.java │ └── resources │ └── META-INF │ ├── spring.factories │ └── swagger-endpoins-default.properties ├── swagger-spring-boot-autoconfigure ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── battcn │ │ └── boot │ │ └── swagger │ │ ├── annotation │ │ └── ApiOrder.java │ │ ├── autoconfigure │ │ └── SwaggerAutoConfiguration.java │ │ ├── configuration │ │ ├── CustomSwagger2DocumentationConfiguration.java │ │ ├── SwaggerBeanValidatorPluginsConfiguration.java │ │ └── SwaggerSecurityFilterPluginsConfiguration.java │ │ ├── model │ │ ├── DataType.java │ │ ├── Order.java │ │ └── ParamType.java │ │ ├── properties │ │ ├── SwaggerProperties.java │ │ └── SwaggerSecurityProperties.java │ │ ├── security │ │ └── GlobalAccess.java │ │ ├── utils │ │ ├── HostNameProvider.java │ │ └── RequestUtils.java │ │ └── web │ │ └── CustomSwagger2Controller.java │ └── resources │ └── META-INF │ └── spring.factories ├── swagger-spring-boot-samples ├── swagger-spring-boot-sample-authorization │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── battcn │ │ │ ├── AuthorizationApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ └── entity │ │ │ ├── ErrorResponseEntity.java │ │ │ └── User.java │ │ └── resources │ │ └── application.properties ├── swagger-spring-boot-sample-basic │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── swagger │ │ │ ├── BasicApplication.java │ │ │ ├── controller │ │ │ ├── order │ │ │ │ └── OrderController.java │ │ │ ├── other │ │ │ │ ├── AllowableValueController.java │ │ │ │ ├── ApiResponseController.java │ │ │ │ ├── BasicController.java │ │ │ │ ├── DefaultValueController.java │ │ │ │ ├── FileUploadController.java │ │ │ │ ├── ImageController.java │ │ │ │ ├── JsonController.java │ │ │ │ ├── PageController.java │ │ │ │ └── TreeController.java │ │ │ └── user │ │ │ │ └── UserController.java │ │ │ ├── entity │ │ │ ├── Address.java │ │ │ ├── AllowableValue.java │ │ │ ├── DefaultPojo.java │ │ │ ├── Message.java │ │ │ ├── Page.java │ │ │ ├── PojoA.java │ │ │ ├── PojoB.java │ │ │ ├── PojoC.java │ │ │ ├── PojoD.java │ │ │ ├── PojoE.java │ │ │ ├── TreeNode.java │ │ │ ├── User.java │ │ │ └── order │ │ │ │ ├── Order.java │ │ │ │ └── OrderLine.java │ │ │ └── utils │ │ │ └── NewVerifyCodeUtils.java │ │ └── resources │ │ ├── application.properties │ │ └── bak_application.yml └── swagger-spring-boot-sample-group │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── battcn │ │ ├── GroupApplication.java │ │ ├── controller │ │ ├── book │ │ │ └── BookController.java │ │ └── user │ │ │ └── UserController.java │ │ └── entity │ │ ├── Book.java │ │ └── User.java │ └── resources │ ├── application.properties │ └── application.yml ├── swagger-spring-boot-starter ├── pom.xml └── src │ └── main │ └── resources │ └── META-INF │ └── spring.provides ├── swagger-vue-ui ├── pom.xml └── src │ └── main │ └── resources │ ├── static │ ├── css │ │ ├── app.af8ba0278559b1d4785696cadf981f59.css │ │ ├── app.af8ba0278559b1d4785696cadf981f59.css.map │ │ ├── app.d3c28ed4bb0b3527dc5d8390a59e1c31.css │ │ ├── app.d3c28ed4bb0b3527dc5d8390a59e1c31.css.map │ │ ├── app.d7cc4ad5a646365a3ab666e99c830358.css │ │ └── app.d7cc4ad5a646365a3ab666e99c830358.css.map │ └── js │ │ ├── app.4988e122a1cd9dc0a961.js │ │ ├── app.4988e122a1cd9dc0a961.js.map │ │ ├── app.69328f568c54c0c4a43d.js │ │ ├── app.69328f568c54c0c4a43d.js.map │ │ ├── app.9f3f4042f1e02d4cd1ca.js │ │ ├── app.9f3f4042f1e02d4cd1ca.js.map │ │ ├── app.fdd8633a1f77f03ae95a.js │ │ ├── app.fdd8633a1f77f03ae95a.js.map │ │ ├── manifest.37a2ecbb1d1b7e6c9ada.js │ │ ├── manifest.37a2ecbb1d1b7e6c9ada.js.map │ │ ├── vendor.3fddc87998db19b981e4.js │ │ ├── vendor.3fddc87998db19b981e4.js.map │ │ ├── vendor.4ff1e304f1dc4912adc6.js │ │ ├── vendor.4ff1e304f1dc4912adc6.js.map │ │ ├── vendor.699c426e2e2aa22c6016.js │ │ ├── vendor.699c426e2e2aa22c6016.js.map │ │ ├── vendor.7420953dba8e1b7c6f64.js │ │ ├── vendor.7420953dba8e1b7c6f64.js.map │ │ ├── vendor.9e78cca78537e890af34.js │ │ └── vendor.9e78cca78537e890af34.js.map │ └── swagger-ui.html └── swagger-vue ├── .babelrc ├── .editorconfig ├── .postcssrc.js ├── build ├── build.js ├── check-versions.js ├── logo.png ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js └── prod.env.js ├── index.html ├── package-lock.json ├── package.json └── src ├── App.vue ├── api ├── accounts.js ├── config.js ├── data.js └── debug_request.js ├── common └── util.js ├── main.js ├── pages ├── about │ ├── index.vue │ └── status.vue ├── util │ ├── operate │ │ ├── authorizations.vue │ │ ├── pop_ups.vue │ │ └── search.vue │ └── view │ │ ├── form_fold.vue │ │ └── json_view.vue └── view │ ├── commit.vue │ ├── info.vue │ ├── list.vue │ └── login.vue ├── router └── index.js └── store ├── actions.js ├── getters.js ├── index.js ├── mutations.js ├── mutations_types.js └── state.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | /dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Editor directories and files 9 | .idea 10 | .vscode 11 | *.suo 12 | *.ntvs* 13 | *.njsproj 14 | *.sln 15 | 16 | # maven # 17 | target 18 | logs 19 | 20 | # eclipse # 21 | .settings 22 | .project 23 | .classpath 24 | .log 25 | 26 | # windows # 27 | Thumbs.db 28 | 29 | # Mac # 30 | .DS_Store 31 | 32 | # Package Files # 33 | *.war 34 | *.ear 35 | 36 | # idea # 37 | *.iml 38 | .idea/ 39 | overlays 40 | bin 41 | 42 | # vue # 43 | /dist/* 44 | /dist/*/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 简介 # 2 | 3 | > 什么是 swagger? 4 | 5 | **`Swagger` 是一款自动生成在线文档 + 接口调试的工具。在 WEB 开发中不可否认的是我们需要给客户端提供 API 接口,这个时候需要借助 postman、rap 等工具 6 | 进行调试,以便于接口能正常交付给客户端人员,用过其它工具的应该知道一个 POST 请求一堆参数是非常枯燥且烦人的事情,而 swagger 就是让你摆脱这种束缚感....** 7 | 8 | > 项目群 9 | 10 | **近期询问 `swagger-spring-boot-starter` 的朋友越来越多,所以就创建了一个意见反馈群(`QQ群:868804589`),BUG反馈和优化/美化的建议都可以在群里进行交流** 11 | 12 | > 源码地址 13 | 14 | - GitHub:[https://github.com/battcn/swagger-spring-boot](https://github.com/battcn/swagger-spring-boot "https://github.com/battcn/swagger-spring-boot") 15 | - 码云:[https://gitee.com/battcn/spring-boot-starter-swagger/](https://gitee.com/battcn/spring-boot-starter-swagger/ "https://gitee.com/battcn/spring-boot-starter-swagger/") 16 | 17 | `swagger-spring-boot-starter` 是一款建立在`swagger`基础之上的工具包,利用SpringBoot自动装配的特性,简化了传统`swagger`的繁琐配置 18 | 19 | > 项目介绍 20 | 21 | - **`swagger-vue` :采用 Vue 编写的源代码,如果您对UI有更好的想法或者建议可以在该项目上进行扩展,它就是 UI 的源文件** 22 | - **`swagger-vue-ui` :编译后的纯 HTML 文件,如果你对 `swagger-spring-boot-starter` 包中的 UI 感到不满,你也可以选择排除 `swagger-vue-ui` 然后用第三方的...** 23 | - **`swagger-spring-boot-starter` : 自动装配 swagger 的扩展包** 24 | 25 | 有兴趣扩展自己的Starter包的可以参考文章:[编写自己的starter项目](http://blog.battcn.com/2017/07/13/springboot/springboot-starter-swagger/ "编写自己的starter项目") 26 | 27 | **如果该项目对您有帮助,欢迎Fork和Star,有疑问可以加 `QQ:1837307557`一起交流 ,如发现项目BUG可以提交`Issue`** 28 | 29 | # 使用 # 30 | 31 | **1.X 版本需要在启动类添加 `@EnableSwagger2Doc` 但是 2.X 版本后无需添加,请知晓...** 32 | 33 | - 在`pom.xml`中引入依赖: 34 | 35 | ``` xml 36 | 37 | com.battcn 38 | swagger-spring-boot-starter 39 | 2.1.5-RELEASE 40 | 41 | ``` 42 | 43 | > 中文乱码 44 | 45 | 如果遇到中文乱码,请确保自己的资源文件是 `UTF-8` 然后添加以下配置(一般情况只要自身环境正确,无需额外配置) 46 | 47 | ``` properties 48 | server.tomcat.uri-encoding=UTF-8 49 | spring.http.encoding.force=true 50 | spring.http.encoding.enabled=true 51 | spring.http.encoding.charset=UTF-8 52 | spring.messages.encoding=UTF-8 53 | ``` 54 | 55 | > 访问 404 56 | 57 | 如果遇到 访问 `swagger-ui.html` 404 的问题,尝试如下方案 58 | 59 | ``` java 60 | import org.springframework.context.annotation.Configuration; 61 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 62 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 63 | 64 | /** 65 | * 解决 swagger-ui.html 访问路径 404 问题 66 | * 67 | * @author Levin 68 | */ 69 | @Configuration 70 | public class SwaggerMvnConfiguration extends WebMvcConfigurationSupport { 71 | 72 | @Override 73 | protected void addResourceHandlers(ResourceHandlerRegistry registry) { 74 | registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0); 75 | } 76 | 77 | } 78 | ``` 79 | 80 | 81 | 82 | - 在`application.yml`中添加 83 | 84 | ``` yaml 85 | spring: 86 | swagger: 87 | enabled: true 88 | ``` 89 | 90 | - 在`application.properties`中添加 91 | 92 | ``` properties 93 | spring.swagger.enabled=true 94 | ``` 95 | 96 | 97 | # 更新记录 # 98 | ``` 99 | 2.1.5 100 | 发布时间:2019-03-04 101 | 更新内容: 102 | 1.修复当前 issues 103 | 2.新增接口搜索功能 104 | 3.优化VUE代码 105 | 4.最近在和公司前端大佬一起讨论代码重构和新版本UI渲染的问题, 106 | 同时2.1.5页是最稳定版本,届时没有BUG的情况下会重心在新版本研发 107 | 2.1.3 108 | 发布时间:2018-12-27 109 | 更新内容: 110 | 1.修复多层`content-path`时,路径404BUG 111 | 2.修复嵌套实体时,`@ApiModelProperty` 必填项显示错误 112 | 3.修复新版UI无缩进问题 113 | 4.修复接口过多情况下,未出现滚动条BUG 114 | 5.当接口类型是 `JAVA POJO`时,渲染的对象添加颜色区分 115 | 6.UI自适应优化,在不同分辨率下显示更加友好 116 | 7.UI兼容性优化,支持在IE11,EDGE等浏览器显示 117 | 8.致歉:近期较忙,所以发布周期延后,十分抱歉 118 | 2.1.2 119 | 发布时间:2018-11-14 120 | 更新内容: 121 | 1.解决调试面板 String 类型数据不显示 122 | 2.解决请求参数为 JSONObject时 没有按 JSON 传输 123 | 3.调试接口界面中 请求参数值可以添加 @ApiModelProperty 注解中 example 配置的默认值 124 | 2.1.1 125 | 发布时间:2018-11-08 126 | 更新内容: 127 | 1.调试面板JSON渲染美化 128 | 2.美化登陆页面UI 129 | 3.修复 TreeNode 数据结构导致内存溢出BUG 130 | 4.优化VUE的包目录结构和代码风格 131 | 2.1.0 132 | 发布时间:2018-09-22 133 | 更新内容: 134 | 1.调试面板JSON渲染美化 135 | 2.修复授权模式下任意密码可以登陆问题 136 | 3.修复ApiModelProperty#required 不生效问题 137 | 2.0.7 138 | 发布时间:2018-08-17 139 | 更新内容: 140 | 1.解决无请求参数无法调试,js报错 141 | 2.解决编辑 json 会导致 json 加一个双引号传输 142 | 2.0.6 143 | 发布时间:2018-07-25 144 | 更新内容: 145 | 1.解决请求错误时,异常信息不渲染的BUG 146 | 2.优化登陆保存策略 147 | 2.0.5 148 | 发布时间:2018-07-24 149 | 更新内容: 150 | 1.修复 spring.swagger.host 导致调试面板失效BUG 151 | 2.0.4 152 | 发布时间:2018-07-23 153 | 更新内容: 154 | 1.修改未自动注入BUG(在2.0.3中需要写明 ComponentScan) 155 | 2.0.2(具体效果看 samples-basic 中的项目示例) 156 | 2.0.3 157 | 发布时间:2018-07-17 158 | 更新内容: 159 | 1.UI美化 160 | 2.路由优化 161 | 3.文件上传控件美化 162 | 2.0.2(具体效果看 samples-basic 中的项目示例) 163 | 发布时间:2018年07月10日 164 | 更新内容: 165 | 1.UI添加响应结果 166 | 2.UI添加全局认证窗口 167 | 3.修复接口过多导致内存溢出泄露BUG 168 | 4.优化代码风格与标准 169 | 5.美化弹窗 170 | 6.添加安全验证过滤器(这样一来即使你想线上使用 swagger 一样可以) 171 | 7.登陆UI,保障接口安全 172 | 8.添加请求响应时间 173 | 9.升级Spring Boot 版本为 2.0.3-RELEASE 174 | 2.0.1 175 | 发布时间:2018年06月19日 176 | 更新内容: 177 | 1.重写UI 178 | 2.升级Spring Boot 为2.0.2 179 | 3.支持接口全局认证(设置一次 Token 需验证的地址自动将值写入到请求头/请求体中) 180 | 4.全局响应返回 181 | 5.支持可选的 Bean 验证插件; 182 | 由于日常开发中发现默认启动的验证插件扫描耗时比较久(由于我电脑弱,扫描时间大概在3-5秒...) 183 | 故而将插件修改为可选的,默认是关闭 184 | 6.支持选项卡切换 185 | 7.修复多余的斜杠 186 | 1.4.5 187 | 发布时间:2018年04月26日 188 | 更新内容: 189 | 1.解决配置 `context-path` 导致 `swagger-ui.html` 无法显示BUG 190 | 1.4.4 191 | 发布时间:2018年01月05日 192 | 更新内容: 193 | 1.优化选项卡切换 194 | 1.4.3 195 | 发布时间:2017年12月22日 196 | 更新内容: 197 | 1.修复CRUL口令 198 | 2.提升操作体验 199 | 1.4.2 200 | 发布时间:2017年12月15日 201 | 更新内容: 202 | 1.修复CRUL口令 203 | 2.渲染菜单列表颜色 204 | 1.4.1 205 | 发布时间:2017年12月13日 206 | 更新内容: 207 | 1.修复CRUL口令 208 | 2.修复DELETE类型请求部分存在404问题 209 | 1.4.0 210 | 发布时间:2017年12月14日 211 | 更新内容: 212 | 1.PATCH无法正确渲染 213 | 1.3.9 214 | 发布时间:2017年9月17日 215 | 更新内容: 216 | 1.修复对象深度拷贝 217 | 1.3.8 218 | 发布时间:2017年12月8日 219 | 更新内容: 220 | 1. 解决1.1.0发版中的bug 221 | 1.1.0 222 | 发布时间:2017年12月1日 223 | 更新内容: 224 | 1. 完成基础功能 225 | ``` 226 | 227 | # 重写UI # 228 | 229 | > 操作风格 - 2.0.2 版本 230 | 231 | ``` java 232 | # 2.0.3 版本新特性(开启后访问 swagger-ui.html 会自动路由到登陆页面,保障接口信息不被暴露) 233 | spring.swagger.security.filter-plugin=true 234 | # 配置账号密码 235 | spring.swagger.security.username=battcn 236 | spring.swagger.security.password=battcn 237 | ``` 238 | 239 | ![接口说明](doc/img/2_4.png) 240 | 241 | > 操作风格 - 2.0.1 版本 242 | 243 | ``` java 244 | # 配置 245 | spring.swagger.api-key.key-name=myToken 246 | # 2.0.1 版本新特性 (支持可选的 Bean 验证插件) 247 | spring.swagger.validator-plugin=false 248 | # 定义全局响应返回 249 | spring.swagger.global-response-messages.POST[0].code=400 250 | spring.swagger.global-response-messages.POST[0].message=server response 400 251 | spring.swagger.global-response-messages.POST[1].code=404 252 | spring.swagger.global-response-messages.POST[1].message=server response 404 253 | ``` 254 | 255 | ![接口说明](doc/img/2_1.png) 256 | 257 | ![接口说明](doc/img/2_2.png) 258 | 259 | ![接口说明](doc/img/2_3.png) 260 | 261 | 262 | > 操作风格 - 1.4.3支持 263 | 264 | ![接口说明](doc/img/4.png) 265 | 266 | > 接口说明:折叠式Model 267 | 268 | ![接口说明](doc/img/1.png) 269 | 270 | 271 | > 接口说明:折叠式表单响应内容,告别长长的滚动条 272 | 273 | ![接口说明](doc/img/2.png) 274 | 275 | > 在线调试 276 | 277 | ![在线调试](doc/img/3.png) 278 | 279 | 280 | ## 配置说明 ## 281 | 282 | `spring.swagger.enabled`:提供该配置目的是方便多环境关闭,一般生产环境中不会暴露它,这时候就可以通过 `java -jar xx.jar --spring.swagger.enabled=false` 动态关闭,也可以在多环境配置写好 283 | 284 | 285 | ### properties ### 286 | 287 | ``` 288 | spring.swagger.enabled=是否启用swagger,默认:true 289 | spring.swagger.title=标题 290 | spring.swagger.description=描述信息 291 | spring.swagger.version=版本 292 | spring.swagger.license=许可证 293 | spring.swagger.licenseUrl=许可证URL 294 | spring.swagger.termsOfServiceUrl=服务条款URL 295 | spring.swagger.contact.name=维护人 296 | spring.swagger.contact.url=维护人URL 297 | spring.swagger.contact.email=维护人email 298 | spring.swagger.base-package=swagger扫描的基础包,默认:全扫描 299 | spring.swagger.base-path=需要处理的基础URL规则,默认:/** 300 | spring.swagger.exclude-path=需要排除的URL规则,默认:空 301 | spring.swagger.host=文档的host信息,默认:空 302 | spring.swagger.globalOperationParameters[0].name=参数名 303 | spring.swagger.globalOperationParameters[0].description=描述信息 304 | spring.swagger.globalOperationParameters[0].modelRef=指定参数类型 305 | spring.swagger.globalOperationParameters[0].parameterType=指定参数存放位置,参考ParamType:(header,query,path,body,form) 306 | spring.swagger.globalOperationParameters[0].required=指定参数是否必传,默认false 307 | #下面分组是 308 | spring.swagger.groups..basePackage=swagger扫描的路径 309 | #比如 310 | spring.swagger.groups.基础信息.basePackage=com.battcn.controller.basic 311 | 312 | # 关闭 JSR 313 | spring.swagger.validator-plugin=false 314 | # 全局消息体 315 | spring.swagger.global-response-messages.GET[0].code=400 316 | spring.swagger.global-response-messages.GET[0].message=server response 400 317 | spring.swagger.global-response-messages.POST[0].code=400 318 | spring.swagger.global-response-messages.POST[0].message=server response 400 319 | spring.swagger.global-response-messages.POST[1].code=404 320 | spring.swagger.global-response-messages.POST[1].message=server response 404 321 | ``` 322 | 323 | 324 | ### yaml ### 325 | 326 | 以下为 `application.yml` 配置示例 327 | 328 | ``` yaml 329 | spring: 330 | swagger: 331 | enabled: true 332 | title: 标题 333 | description: 描述信息 334 | version: 系统版本号 335 | contact: 336 | name: 维护者信息 337 | base-package: swagger扫描的基础包,默认:全扫描(分组情况下此处可不配置) 338 | #全局参数,比如Token之类的验证信息可以全局话配置 339 | global-operation-parameters: 340 | - description: 'Token信息,必填项' 341 | modelRef: 'string' 342 | name: 'Authorization' 343 | parameter-type: 'header' 344 | required: true 345 | groups: 346 | basic-group: 347 | base-package: com.battcn.controller.basic 348 | system-group: 349 | base-package: com.battcn.controller.system 350 | ``` 351 | 352 | 353 | # 贡献者 # 354 | 355 | Levin:1837307557@qq.com 356 | 357 | - 个人博文:[http://blog.battcn.com](http://blog.battcn.com "http://blog.battcn.com") 358 | 359 | _Rock:995269937@qq.com 360 | 361 | 362 | # 常用注解说明 # 363 | 364 | * `@Api`:一般用于Controller中,用于接口分组。(**`如:@Api(value = "用户接口", description = "用户接口", tags = {"1.1.0"})`** 365 | 366 | * `@ApiOperation`:接口说明,用于api方法上。(**`如: @ApiOperation(value = "用户查询", notes = "根据ID查询用户信息")`**) 367 | 368 | * `@ApiImplicitParam`:参数说明,适用于只有一个请求参数,主要参数 369 | 370 | * `@ApiImplicitParams`:多个参数说明,主要参数参考上面`@ApiImplicitParam` 371 | 372 | * `@ApiModel`:实体类说明 373 | 374 | * `@ApiModelProperty`:实体参数说明 375 | 376 | 377 | # 如何参与 # 378 | 379 | 有兴趣的可以联系本人(Pull Request),参与进来一起开发,美化UI与配置项一起完善 380 | -------------------------------------------------------------------------------- /doc/img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/1.png -------------------------------------------------------------------------------- /doc/img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/2.png -------------------------------------------------------------------------------- /doc/img/2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/2_1.png -------------------------------------------------------------------------------- /doc/img/2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/2_2.png -------------------------------------------------------------------------------- /doc/img/2_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/2_3.png -------------------------------------------------------------------------------- /doc/img/2_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/2_4.png -------------------------------------------------------------------------------- /doc/img/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/3.png -------------------------------------------------------------------------------- /doc/img/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/doc/img/4.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.battcn 8 | swagger-spring-boot 9 | 2.1.5-RELEASE 10 | pom 11 | swagger-spring-boot 12 | 13 | https://github.com/battcn/swagger-spring-boot-starter.git 14 | 基于swagger springfox做的一款扩展工具包 15 | 16 | 17 | swagger-spring-boot-autoconfigure 18 | swagger-spring-boot-actuator 19 | swagger-spring-boot-starter 20 | swagger-vue-ui 21 | 22 | 23 | 24 | battcn开源组 25 | http://blog.battcn.com 26 | 27 | 28 | 29 | 30 | 31 | The Apache Software License, Version 2.0 32 | http://www.apache.org/licenses/LICENSE-2.0.txt 33 | repo 34 | 35 | 36 | 37 | 38 | http://blog.battcn.com 39 | git@github.com:battcn/swagger-spring-boot.git 40 | https://github.com/battcn/swagger-spring-boot.git 41 | 42 | 43 | 44 | 45 | 唐亚峰 - battcn 46 | 1837307557@qq.com 47 | http://blog.battcn.com 48 | 49 | Java 开发工程师 50 | 51 | 52 | 53 | _Rock 54 | 995269937@qq.com 55 | 56 | 学生 57 | 58 | 59 | 60 | 61 | 62 | 63 | UTF-8 64 | 1.8 65 | 2.8.0 66 | 2.0.3.RELEASE 67 | 68 | true 69 | 70 | 3.0.1 71 | 2.10.4 72 | 1.6 73 | 74 | 75 | 76 | 77 | 78 | io.springfox 79 | springfox-swagger2 80 | ${springfox.version} 81 | 82 | 83 | io.springfox 84 | springfox-bean-validators 85 | ${springfox.version} 86 | 87 | 88 | com.battcn 89 | swagger-vue-ui 90 | ${project.version} 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-dependencies 95 | ${spring-boot.version} 96 | pom 97 | import 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | oss 106 | https://oss.sonatype.org/content/repositories/snapshots/ 107 | 108 | 109 | oss 110 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 111 | 112 | 113 | 114 | 115 | 116 | 117 | oss 118 | 119 | 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-resources-plugin 124 | 125 | UTF-8 126 | 127 | 128 | 129 | org.apache.maven.plugins 130 | maven-source-plugin 131 | 132 | 133 | attach-sources 134 | 135 | jar 136 | 137 | 138 | 139 | 140 | 141 | 142 | org.apache.maven.plugins 143 | maven-compiler-plugin 144 | 145 | ${java.version} 146 | ${java.version} 147 | ${project.build.sourceEncoding} 148 | 149 | 150 | 151 | 152 | org.apache.maven.plugins 153 | maven-source-plugin 154 | ${maven-source-plugin.version} 155 | 156 | 157 | package 158 | 159 | jar-no-fork 160 | 161 | 162 | 163 | 164 | 165 | 166 | org.apache.maven.plugins 167 | maven-javadoc-plugin 168 | 169 | 170 | package 171 | 172 | jar 173 | 174 | 175 | 176 | 177 | 178 | 179 | org.apache.maven.plugins 180 | maven-gpg-plugin 181 | ${maven-gpg-plugin.version} 182 | 183 | 184 | verify 185 | 186 | sign 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | oss 197 | https://oss.sonatype.org/content/repositories/snapshots/ 198 | 199 | 200 | oss 201 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | org.apache.maven.plugins 213 | maven-resources-plugin 214 | 215 | UTF-8 216 | 217 | 218 | 219 | org.apache.maven.plugins 220 | maven-source-plugin 221 | 222 | 223 | attach-sources 224 | 225 | jar 226 | 227 | 228 | 229 | 230 | 231 | 232 | org.apache.maven.plugins 233 | maven-compiler-plugin 234 | 235 | ${java.version} 236 | ${java.version} 237 | ${project.build.sourceEncoding} 238 | 239 | 240 | 241 | 242 | 243 | 244 | -------------------------------------------------------------------------------- /swagger-spring-boot-actuator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.battcn 8 | swagger-spring-boot 9 | 2.1.5-RELEASE 10 | 11 | swagger-spring-boot-actuator 12 | swagger-spring-boot-actuator 13 | jar 14 | ${parent.version} 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | true 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-configuration-processor 25 | true 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | ${project.basedir}/src/main/resources 39 | META-INF/resources/ 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-compiler-plugin 47 | 48 | ${java.version} 49 | ${java.version} 50 | ${project.build.sourceEncoding} 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /swagger-spring-boot-actuator/src/main/java/com/battcn/boot/swagger/actuate/autoconfigure/SwaggerEndpointsAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.actuate.autoconfigure; 2 | 3 | import com.battcn.boot.swagger.actuate.endpoint.SwaggerEndpoint; 4 | import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.PropertySource; 10 | 11 | /** 12 | * @author Levin 13 | * @see Configuration 14 | * @since 2.0.2 15 | */ 16 | @Configuration 17 | @EnableAutoConfiguration 18 | @PropertySource( 19 | name = "Swagger Endpoints Default Properties", 20 | value = "classpath:/META-INF/resources/META-INF/swagger-endpoins-default.properties") 21 | public class SwaggerEndpointsAutoConfiguration { 22 | 23 | @Bean 24 | @ConditionalOnMissingBean 25 | @ConditionalOnEnabledEndpoint 26 | public SwaggerEndpoint swaggerEndpoint() { 27 | return new SwaggerEndpoint(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /swagger-spring-boot-actuator/src/main/java/com/battcn/boot/swagger/actuate/endpoint/SwaggerEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.actuate.endpoint; 2 | 3 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 4 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import java.util.LinkedHashMap; 8 | import java.util.Map; 9 | 10 | import static com.battcn.boot.swagger.actuate.endpoint.SwaggerEndpoint.SWAGGER_ENDPOINT_ID; 11 | 12 | /** 13 | * @author Levin 14 | * @see Configuration 15 | * @since 2.0.2 16 | */ 17 | @Endpoint(id = SWAGGER_ENDPOINT_ID) 18 | public class SwaggerEndpoint { 19 | 20 | static final String SWAGGER_ENDPOINT_ID = "swagger"; 21 | private static final String SWAGGER_SPRING_BOOT_VERSION = "2.0.2-RELEASE"; 22 | private static final String SWAGGER_VERSION = "2.8.0"; 23 | private static final String SWAGGER_SPRING_BOOT_GITHUB_URL = "https://github.com/battcn/swagger-spring-boot"; 24 | private static final String SWAGGER_SPRING_BOOT_ISSUES_URL = SWAGGER_SPRING_BOOT_GITHUB_URL + "/issues"; 25 | 26 | @ReadOperation 27 | public Map invoke() { 28 | 29 | Map metaData = new LinkedHashMap<>(); 30 | 31 | metaData.put("timestamp", System.currentTimeMillis()); 32 | 33 | Map versions = new LinkedHashMap<>(); 34 | versions.put("swagger-spring-boot", SWAGGER_SPRING_BOOT_VERSION); 35 | versions.put("swagger", SWAGGER_VERSION); 36 | 37 | Map urls = new LinkedHashMap<>(); 38 | urls.put("github", SWAGGER_SPRING_BOOT_GITHUB_URL); 39 | urls.put("issues", SWAGGER_SPRING_BOOT_ISSUES_URL); 40 | 41 | metaData.put("versions", versions); 42 | metaData.put("urls", urls); 43 | metaData.put("email", "1837307557@qq.com"); 44 | return metaData; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /swagger-spring-boot-actuator/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # Auto Configure 2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 3 | com.battcn.boot.swagger.actuate.autoconfigure.SwaggerEndpointsAutoConfiguration -------------------------------------------------------------------------------- /swagger-spring-boot-actuator/src/main/resources/META-INF/swagger-endpoins-default.properties: -------------------------------------------------------------------------------- 1 | 2 | management.endpoint.dubbo.enabled=true 3 | 4 | management.endpoints.web.exposure.include=swagger -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.battcn 8 | swagger-spring-boot 9 | 2.1.5-RELEASE 10 | 11 | swagger-spring-boot-autoconfigure 12 | swagger-spring-boot-autoconfigure 13 | jar 14 | ${parent.version} 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | true 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-configuration-processor 25 | true 26 | 27 | 28 | io.springfox 29 | springfox-swagger2 30 | 31 | 32 | io.springfox 33 | springfox-bean-validators 34 | 35 | 36 | com.battcn 37 | swagger-vue-ui 38 | 39 | 40 | org.projectlombok 41 | lombok 42 | provided 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/annotation/ApiOrder.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.annotation; 2 | 3 | import org.springframework.core.Ordered; 4 | 5 | import java.lang.annotation.*; 6 | 7 | @Retention(RetentionPolicy.RUNTIME) 8 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) 9 | @Documented 10 | public @interface ApiOrder { 11 | 12 | /** 13 | * The order value. 14 | *

Default is {@link Ordered#LOWEST_PRECEDENCE}. 15 | * @see Ordered#getOrder() 16 | */ 17 | int value() default Ordered.LOWEST_PRECEDENCE; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/configuration/CustomSwagger2DocumentationConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.configuration; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * @author Levin 8 | * @since 2018/7/6 0006 9 | */ 10 | @Configuration 11 | @ComponentScan("com.battcn.boot.swagger.web") 12 | public class CustomSwagger2DocumentationConfiguration { 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/configuration/SwaggerBeanValidatorPluginsConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.configuration; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; 6 | 7 | /** 8 | * @author Levin 9 | * @since 2.0.2 10 | */ 11 | @Configuration 12 | @ConditionalOnProperty(name = {"spring.swagger.enabled", "spring.swagger.validator-plugin"}, havingValue = "true") 13 | public class SwaggerBeanValidatorPluginsConfiguration extends BeanValidatorPluginsConfiguration { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/configuration/SwaggerSecurityFilterPluginsConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.configuration; 2 | 3 | import com.battcn.boot.swagger.utils.RequestUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import javax.servlet.*; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.http.HttpSession; 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Levin 15 | * @since 2.0.2 16 | */ 17 | public class SwaggerSecurityFilterPluginsConfiguration implements Filter { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(SwaggerSecurityFilterPluginsConfiguration.class); 20 | 21 | @Override 22 | public void init(FilterConfig filterConfig) throws ServletException { 23 | logger.info("==================== init swagger security filter plugin ===================="); 24 | } 25 | 26 | @Override 27 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 28 | final HttpServletResponse response = (HttpServletResponse) servletResponse; 29 | final HttpServletRequest request = (HttpServletRequest) servletRequest; 30 | final HttpSession session = request.getSession(); 31 | if (session == null || session.getAttribute(session.getId()) == null) { 32 | RequestUtils.writeForbidden(response); 33 | } 34 | filterChain.doFilter(servletRequest, servletResponse); 35 | } 36 | 37 | @Override 38 | public void destroy() { 39 | logger.info("==================== destroy swagger security filter plugin ===================="); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/model/DataType.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.model; 2 | 3 | 4 | /** 5 | * 方便Swagger 中 @ApiImplicitParam(paramType = DataType.HEADER) 6 | * 7 | * @author Levin 8 | * @since 2.0.2 9 | */ 10 | public final class DataType { 11 | 12 | public final static String STRING = "String"; 13 | public final static String INT = "int"; 14 | public final static String LONG = "long"; 15 | public final static String DOUBLE = "double"; 16 | public final static String FLOAT = "float"; 17 | public final static String BYTE = "byte"; 18 | public final static String BOOLEAN = "boolean"; 19 | public final static String ARRAY = "array"; 20 | public final static String BINARY = "binary"; 21 | public final static String DATETIME = "dateTime"; 22 | public final static String PASSWORD = "password"; 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/model/Order.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author Levin 9 | * @since 2018/12/6 0006 10 | */ 11 | @Data 12 | public class Order { 13 | 14 | private List tags; 15 | private int order = 0; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/model/ParamType.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.model; 2 | 3 | /** 4 | * 方便Swagger 中 @ApiImplicitParam(paramType = ApiParamType.HEADER) 5 | * 6 | * @author Levin 7 | */ 8 | public final class ParamType { 9 | 10 | public final static String QUERY = "query"; 11 | public final static String HEADER = "header"; 12 | public final static String PATH = "path"; 13 | public final static String BODY = "body"; 14 | public final static String FORM = "form"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/properties/SwaggerProperties.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.properties; 2 | 3 | import com.google.common.collect.Maps; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | 9 | import java.util.ArrayList; 10 | import java.util.LinkedHashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | 15 | /** 16 | * @author Levin 17 | */ 18 | @Data 19 | @ConfigurationProperties("spring.swagger") 20 | public class SwaggerProperties { 21 | 22 | 23 | private static final String DEFAULT_VALUE = ""; 24 | 25 | /** 26 | * 是否开启swagger 27 | */ 28 | private Boolean enabled; 29 | /** 30 | * 标题 31 | */ 32 | private String title = DEFAULT_VALUE; 33 | /** 34 | * 描述 35 | */ 36 | private String description = DEFAULT_VALUE; 37 | /** 38 | * 版本 39 | */ 40 | private String version = DEFAULT_VALUE; 41 | /** 42 | * 许可证 43 | */ 44 | private String license = DEFAULT_VALUE; 45 | /** 46 | * 许可证URL 47 | */ 48 | private String licenseUrl = DEFAULT_VALUE; 49 | /** 50 | * 服务条款URL 51 | */ 52 | private String termsOfServiceUrl = DEFAULT_VALUE; 53 | 54 | /** 55 | * swagger会解析的包路径 56 | */ 57 | private String basePackage = DEFAULT_VALUE; 58 | 59 | /** 60 | * host信息 61 | */ 62 | private String host = DEFAULT_VALUE; 63 | 64 | /** 65 | * 联系人信息 66 | */ 67 | private Contact contact = new Contact(); 68 | 69 | /** 70 | * swagger会解析的url规则 71 | */ 72 | private List basePath = new ArrayList<>(); 73 | /** 74 | * 在basePath基础上需要排除的url规则 75 | */ 76 | private List excludePath = new ArrayList<>(); 77 | 78 | /** 79 | * 分组文档 80 | */ 81 | private Map groups = new LinkedHashMap<>(); 82 | 83 | 84 | /** 85 | * 全局参数配置 86 | */ 87 | private List globalOperationParameters; 88 | 89 | /** 90 | * 全局响应配置 91 | */ 92 | private Map> globalResponseMessages = Maps.newLinkedHashMap(); 93 | 94 | /** 95 | * 是否开启验证插件支持(默认关闭) 96 | */ 97 | private boolean validatorPlugin = false; 98 | 99 | public boolean isValidatorPlugin() { 100 | return validatorPlugin; 101 | } 102 | 103 | public void setValidatorPlugin(boolean validatorPlugin) { 104 | this.validatorPlugin = validatorPlugin; 105 | } 106 | 107 | 108 | private ApiKey apiKey; 109 | 110 | @Data 111 | public static class ApiKey { 112 | 113 | /** 114 | * 鉴权策略ID;对应 SecurityReferences ID 115 | */ 116 | private String name = "X-Authorization"; 117 | 118 | /** 119 | * 传递的鉴权参数字段名 120 | */ 121 | private String keyName = "token"; 122 | 123 | 124 | /** 125 | * 自定义匹配路径的正则(如:/anyPath.* 或者 ^.*$) 默认匹配所有 126 | */ 127 | private String authRegex = "^.*$"; 128 | 129 | /** 130 | * 传递参数的类型;默认 header 存放 131 | */ 132 | private String paramType = "header"; 133 | } 134 | 135 | @Data 136 | public static class ResponseMessageBody { 137 | /** 138 | * 状态码 139 | */ 140 | private int code; 141 | /** 142 | * 响应的消息内容 143 | */ 144 | private String message; 145 | /** 146 | * 响应体(对象) 147 | */ 148 | private String modelRef; 149 | } 150 | 151 | @Data 152 | public static class GlobalOperationParameter { 153 | 154 | /** 155 | * 参数名 156 | */ 157 | private String name; 158 | 159 | /** 160 | * 描述信息 161 | */ 162 | private String description; 163 | 164 | /** 165 | * 指定参数类型 166 | */ 167 | private String modelRef; 168 | 169 | /** 170 | * 参数存放位置: 171 | * 172 | * @see ParamType 173 | */ 174 | private String parameterType; 175 | 176 | /** 177 | * 是否必须传 178 | */ 179 | private Boolean required = false; 180 | 181 | } 182 | 183 | @Data 184 | @NoArgsConstructor 185 | @ConfigurationProperties("spring.swagger.groups") 186 | public static class GroupInfo { 187 | 188 | /** 189 | * 标题 190 | */ 191 | private String title = DEFAULT_VALUE; 192 | /** 193 | * 描述 194 | */ 195 | private String description = DEFAULT_VALUE; 196 | 197 | /** 198 | * 版本 199 | */ 200 | private String version = DEFAULT_VALUE; 201 | 202 | /** 203 | * 许可证 204 | */ 205 | private String license = DEFAULT_VALUE; 206 | 207 | /** 208 | * 许可证URL 209 | */ 210 | private String licenseUrl = DEFAULT_VALUE; 211 | 212 | /** 213 | * 服务条款URL 214 | */ 215 | private String termsOfServiceUrl = DEFAULT_VALUE; 216 | 217 | private Contact contact = new Contact(); 218 | 219 | /** 220 | * swagger会解析的包路径 221 | */ 222 | private String basePackage = DEFAULT_VALUE; 223 | 224 | /** 225 | * swagger会解析的url规则 226 | */ 227 | private List basePath = new ArrayList<>(); 228 | /** 229 | * 在basePath基础上需要排除的url规则 230 | */ 231 | private List excludePath = new ArrayList<>(); 232 | 233 | /** 234 | * 分组里的全局参数 235 | */ 236 | private List globalOperationParameters; 237 | 238 | } 239 | 240 | @Data 241 | @NoArgsConstructor 242 | public static class Contact { 243 | /** 244 | * 联系人 245 | */ 246 | private String name = DEFAULT_VALUE; 247 | /** 248 | * 联系人url 249 | */ 250 | private String url = DEFAULT_VALUE; 251 | /** 252 | * 联系人email 253 | */ 254 | private String email = DEFAULT_VALUE; 255 | 256 | } 257 | 258 | } -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/properties/SwaggerSecurityProperties.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.properties; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | 6 | /** 7 | * @author Levin 8 | */ 9 | @ConfigurationProperties("spring.swagger.security") 10 | public class SwaggerSecurityProperties { 11 | 12 | /** 13 | * 安全过滤器插件开关 14 | */ 15 | private boolean filterPlugin; 16 | /** 17 | * 用户名 18 | */ 19 | private String username; 20 | /** 21 | * 密码 22 | */ 23 | private String password; 24 | 25 | public boolean isFilterPlugin() { 26 | return filterPlugin; 27 | } 28 | 29 | public void setFilterPlugin(boolean filterPlugin) { 30 | this.filterPlugin = filterPlugin; 31 | } 32 | 33 | public String getUsername() { 34 | return username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | public void setPassword(String password) { 46 | this.password = password; 47 | } 48 | } -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/security/GlobalAccess.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.security; 2 | 3 | import com.battcn.boot.swagger.properties.SwaggerProperties; 4 | import springfox.documentation.builders.PathSelectors; 5 | import springfox.documentation.service.ApiKey; 6 | import springfox.documentation.service.AuthorizationScope; 7 | import springfox.documentation.service.SecurityReference; 8 | import springfox.documentation.spi.service.contexts.SecurityContext; 9 | 10 | import java.util.List; 11 | 12 | import static com.google.common.collect.Lists.newArrayList; 13 | 14 | /** 15 | * 安全相关 16 | * 17 | * @author Levin 18 | * @since 2018/6/14 0014 19 | */ 20 | public class GlobalAccess { 21 | 22 | private final SwaggerProperties swaggerProperties; 23 | 24 | public GlobalAccess(SwaggerProperties swaggerProperties) { 25 | this.swaggerProperties = swaggerProperties; 26 | } 27 | 28 | 29 | public ApiKey apiKey() { 30 | final SwaggerProperties.ApiKey apiKey = swaggerProperties.getApiKey(); 31 | return new ApiKey(apiKey.getName(), apiKey.getKeyName(), apiKey.getParamType()); 32 | } 33 | 34 | /** 35 | * 采用正则表达式进行 HTTP API 全局鉴权接口配置;默认 any 所有接口都授权 36 | * 其中 securityReferences 为配置启用的鉴权策略 37 | * 38 | * @return SecurityContext 39 | */ 40 | public SecurityContext securityContext() { 41 | final SwaggerProperties.ApiKey apiKey = swaggerProperties.getApiKey(); 42 | return SecurityContext.builder() 43 | .securityReferences(defaultAuth(apiKey)) 44 | .forPaths(PathSelectors.regex(apiKey.getAuthRegex())).build(); 45 | } 46 | 47 | /** 48 | * 配置默认的全局鉴权策略; SecurityReference 中 reference 参数需要与 ApiKey.name 保持一致 49 | * 50 | * @return List 51 | */ 52 | private List defaultAuth(SwaggerProperties.ApiKey apiKey) { 53 | AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); 54 | return newArrayList(new SecurityReference(apiKey.getName(), new AuthorizationScope[]{authorizationScope})); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/utils/HostNameProvider.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.utils; 2 | 3 | import org.springframework.http.server.ServletServerHttpRequest; 4 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 5 | import org.springframework.web.util.UriComponents; 6 | import org.springframework.web.util.UriComponentsBuilder; 7 | import org.springframework.web.util.UrlPathHelper; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | import static org.springframework.util.StringUtils.hasText; 12 | import static org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromContextPath; 13 | 14 | /** 15 | * @author Levin 16 | * @since 2018/12/6 0006 17 | */ 18 | public class HostNameProvider { 19 | public HostNameProvider() { 20 | throw new UnsupportedOperationException(); 21 | } 22 | 23 | public static UriComponents componentsFrom( 24 | HttpServletRequest request, 25 | String basePath) { 26 | 27 | ServletUriComponentsBuilder builder = fromServletMapping(request, basePath); 28 | 29 | UriComponents components = UriComponentsBuilder.fromHttpRequest( 30 | new ServletServerHttpRequest(request)) 31 | .build(); 32 | 33 | String host = components.getHost(); 34 | if (!hasText(host)) { 35 | return builder.build(); 36 | } 37 | 38 | builder.host(host); 39 | builder.port(components.getPort()); 40 | 41 | return builder.build(); 42 | } 43 | 44 | private static ServletUriComponentsBuilder fromServletMapping( 45 | HttpServletRequest request, 46 | String basePath) { 47 | 48 | ServletUriComponentsBuilder builder = fromContextPath(request); 49 | 50 | builder.replacePath(prependForwardedPrefix(request, basePath)); 51 | if (hasText(new UrlPathHelper().getPathWithinServletMapping(request))) { 52 | builder.path(request.getServletPath()); 53 | } 54 | 55 | return builder; 56 | } 57 | 58 | private static String prependForwardedPrefix( 59 | HttpServletRequest request, 60 | String path) { 61 | 62 | String prefix = request.getHeader("X-Forwarded-Prefix"); 63 | if (prefix != null) { 64 | return prefix + path; 65 | } else { 66 | return path; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/utils/RequestUtils.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.utils; 2 | 3 | import com.battcn.boot.swagger.web.CustomSwagger2Controller; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.MediaType; 8 | 9 | import javax.servlet.ServletOutputStream; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author Levin 15 | * @since 2018/7/6 0006 16 | */ 17 | public class RequestUtils { 18 | 19 | private RequestUtils() { 20 | } 21 | 22 | public static boolean SWAGGER_IS_LOGIN = false; 23 | 24 | private static final Logger logger = LoggerFactory.getLogger(CustomSwagger2Controller.class); 25 | 26 | public static void writeForbidden(HttpServletResponse response) throws IOException { 27 | final HttpStatus status = HttpStatus.UNAUTHORIZED; 28 | response.setStatus(status.value()); 29 | response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); 30 | ServletOutputStream outputStream = response.getOutputStream(); 31 | String error = "{\"code\":%d,\"message\":\"%s\"}"; 32 | final String format = String.format(error, status.value(), status.getReasonPhrase()); 33 | logger.error(format); 34 | outputStream.write(format.getBytes()); 35 | outputStream.flush(); 36 | outputStream.close(); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/java/com/battcn/boot/swagger/web/CustomSwagger2Controller.java: -------------------------------------------------------------------------------- 1 | package com.battcn.boot.swagger.web; 2 | 3 | import com.battcn.boot.swagger.annotation.ApiOrder; 4 | import com.battcn.boot.swagger.model.Order; 5 | import com.battcn.boot.swagger.properties.SwaggerSecurityProperties; 6 | import com.battcn.boot.swagger.utils.HostNameProvider; 7 | import com.battcn.boot.swagger.utils.RequestUtils; 8 | import com.google.common.base.Strings; 9 | import com.google.common.collect.Lists; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.models.Swagger; 12 | import io.swagger.models.Tag; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 15 | import org.springframework.core.annotation.AnnotationUtils; 16 | import org.springframework.core.env.Environment; 17 | import org.springframework.http.HttpStatus; 18 | import org.springframework.http.MediaType; 19 | import org.springframework.http.ResponseEntity; 20 | import org.springframework.util.StringUtils; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.PostMapping; 23 | import org.springframework.web.bind.annotation.RequestParam; 24 | import org.springframework.web.bind.annotation.RestController; 25 | import org.springframework.web.method.HandlerMethod; 26 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; 27 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 28 | import org.springframework.web.util.UriComponents; 29 | import springfox.documentation.annotations.ApiIgnore; 30 | import springfox.documentation.service.Documentation; 31 | import springfox.documentation.spring.web.DocumentationCache; 32 | import springfox.documentation.spring.web.json.Json; 33 | import springfox.documentation.spring.web.json.JsonSerializer; 34 | import springfox.documentation.spring.web.plugins.Docket; 35 | import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper; 36 | 37 | import javax.servlet.http.HttpServletRequest; 38 | import javax.servlet.http.HttpServletResponse; 39 | import javax.servlet.http.HttpSession; 40 | import java.io.IOException; 41 | import java.util.HashMap; 42 | import java.util.List; 43 | import java.util.Map; 44 | import java.util.Optional; 45 | 46 | import static com.google.common.base.Strings.isNullOrEmpty; 47 | 48 | /** 49 | * @author Levin 50 | * @since 2018/7/6 0006 51 | */ 52 | @ConditionalOnProperty(name = "spring.swagger.enabled", havingValue = "true", matchIfMissing = true) 53 | @RestController 54 | @ApiIgnore 55 | public class CustomSwagger2Controller { 56 | 57 | private static final String DEFAULT = "DEFAULT"; 58 | private static final String V3_SWAGGER_API_DOCS = "/v3/api-docs"; 59 | private static final String V3_SWAGGER_SECURITY_URL = "/v3/swagger-security"; 60 | private static final String V3_SWAGGER_SECURITY_LOGIN_URL = "/v3/swagger-login"; 61 | private final SwaggerSecurityProperties swaggerSecurityProperties; 62 | 63 | private final String hostNameOverride; 64 | private final DocumentationCache documentationCache; 65 | private final ServiceModelToSwagger2Mapper mapper; 66 | private final JsonSerializer jsonSerializer; 67 | private final RequestMappingHandlerMapping requestMappingHandlerMapping; 68 | 69 | @Autowired 70 | public CustomSwagger2Controller(SwaggerSecurityProperties swaggerSecurityProperties, Environment environment, 71 | DocumentationCache documentationCache, 72 | ServiceModelToSwagger2Mapper mapper, 73 | JsonSerializer jsonSerializer, RequestMappingHandlerMapping requestMappingHandlerMapping) { 74 | this.hostNameOverride = environment.getProperty("springfox.documentation.swagger.v2.host", "DEFAULT"); 75 | this.documentationCache = documentationCache; 76 | this.mapper = mapper; 77 | this.jsonSerializer = jsonSerializer; 78 | this.swaggerSecurityProperties = swaggerSecurityProperties; 79 | this.requestMappingHandlerMapping = requestMappingHandlerMapping; 80 | } 81 | 82 | @GetMapping(value = V3_SWAGGER_SECURITY_URL, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) 83 | public ResponseEntity> getCustomDocumentation() { 84 | Map meteData = new HashMap<>(2); 85 | meteData.put("security", swaggerSecurityProperties.isFilterPlugin()); 86 | return new ResponseEntity<>(meteData, HttpStatus.OK); 87 | } 88 | 89 | @PostMapping(value = V3_SWAGGER_SECURITY_LOGIN_URL, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) 90 | public ResponseEntity loginSwagger(HttpSession session, HttpServletResponse response, String username, String password) throws IOException { 91 | if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { 92 | RequestUtils.writeForbidden(response); 93 | } 94 | if (!(username.equals(swaggerSecurityProperties.getUsername()) && password.equals(swaggerSecurityProperties.getPassword()))) { 95 | RequestUtils.writeForbidden(response); 96 | } 97 | if (swaggerSecurityProperties.getUsername().equals(username) && password.equals(swaggerSecurityProperties.getPassword())) { 98 | final String sessionId = session.getId(); 99 | session.setAttribute(sessionId, sessionId); 100 | return new ResponseEntity<>(HttpStatus.OK); 101 | } 102 | return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); 103 | } 104 | 105 | @GetMapping(value = V3_SWAGGER_API_DOCS, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) 106 | public ResponseEntity getDocumentation(@RequestParam(value = "group", required = false) String swaggerGroup, 107 | HttpServletRequest servletRequest) { 108 | String groupName = Optional.ofNullable(swaggerGroup).orElse(Docket.DEFAULT_GROUP_NAME); 109 | Documentation documentation = documentationCache.documentationByGroup(groupName); 110 | if (documentation == null) { 111 | return new ResponseEntity<>(HttpStatus.NOT_FOUND); 112 | } 113 | Swagger swagger = mapper.mapDocumentation(documentation); 114 | swagger.setVendorExtension("x-order-tags", ""); 115 | UriComponents uriComponents = HostNameProvider.componentsFrom(servletRequest, swagger.getBasePath()); 116 | swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath()); 117 | if (isNullOrEmpty(swagger.getHost())) { 118 | swagger.host(hostName(uriComponents)); 119 | } 120 | List orders = findOrder(); 121 | final List tags = swagger.getTags(); 122 | for (Tag tag : tags) { 123 | for (Order order : orders) { 124 | if (order.getTags().contains(tag.getName())) { 125 | tag.setVendorExtension("x-order", order.getOrder()); 126 | } 127 | } 128 | } 129 | return new ResponseEntity<>(jsonSerializer.toJson(swagger), HttpStatus.OK); 130 | } 131 | 132 | private List findOrder() { 133 | List orders = Lists.newArrayList(); 134 | final Map handlerMethods = requestMappingHandlerMapping.getHandlerMethods(); 135 | for (Map.Entry methodEntry : handlerMethods.entrySet()) { 136 | HandlerMethod method = methodEntry.getValue(); 137 | final Class declaringClass = method.getMethod().getDeclaringClass(); 138 | final String simpleName = declaringClass.getSimpleName(); 139 | final ApiOrder apiOrder = AnnotationUtils.findAnnotation(declaringClass, ApiOrder.class); 140 | final Api api = AnnotationUtils.findAnnotation(declaringClass, Api.class); 141 | Order order = new Order(); 142 | if (apiOrder != null) { 143 | order.setOrder(apiOrder.value()); 144 | } 145 | if (api != null) { 146 | order.setTags(Lists.newArrayList(api.tags())); 147 | } else { 148 | // 格式化class 149 | final String lowerCase = simpleName.replaceAll("-", "").toLowerCase(); 150 | order.setTags(Lists.newArrayList(lowerCase)); 151 | } 152 | orders.add(order); 153 | } 154 | return orders; 155 | } 156 | 157 | 158 | private String hostName(UriComponents uriComponents) { 159 | if (DEFAULT.equals(hostNameOverride)) { 160 | String host = uriComponents.getHost(); 161 | int port = uriComponents.getPort(); 162 | if (port > -1) { 163 | return String.format("%s:%d", host, port); 164 | } 165 | return host; 166 | } 167 | return hostNameOverride; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /swagger-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # Auto Configure 2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 3 | com.battcn.boot.swagger.autoconfigure.SwaggerAutoConfiguration,\ 4 | com.battcn.boot.swagger.configuration.CustomSwagger2DocumentationConfiguration -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-authorization/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.0.3.RELEASE 9 | 10 | 11 | com.battcn 12 | swagger-spring-boot-sample-authorization 13 | 0.0.1-SNAPSHOT 14 | jar 15 | 16 | 17 | UTF-8 18 | UTF-8 19 | 1.8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | io.springfox 29 | springfox-swagger2 30 | 2.8.0 31 | 32 | 33 | io.springfox 34 | springfox-swagger-ui 35 | 2.8.0 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-authorization/src/main/java/com/battcn/AuthorizationApplication.java: -------------------------------------------------------------------------------- 1 | package com.battcn; 2 | 3 | import com.fasterxml.classmate.TypeResolver; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.context.request.async.DeferredResult; 11 | import org.springframework.web.cors.CorsConfiguration; 12 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 13 | import org.springframework.web.filter.CorsFilter; 14 | import springfox.documentation.builders.PathSelectors; 15 | import springfox.documentation.builders.RequestHandlerSelectors; 16 | import springfox.documentation.builders.ResponseMessageBuilder; 17 | import springfox.documentation.schema.ModelRef; 18 | import springfox.documentation.schema.WildcardType; 19 | import springfox.documentation.service.ApiKey; 20 | import springfox.documentation.service.AuthorizationScope; 21 | import springfox.documentation.service.SecurityReference; 22 | import springfox.documentation.spi.DocumentationType; 23 | import springfox.documentation.spi.service.contexts.SecurityContext; 24 | import springfox.documentation.spring.web.plugins.Docket; 25 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 26 | 27 | import java.time.LocalDate; 28 | import java.util.List; 29 | 30 | import static com.google.common.collect.Lists.newArrayList; 31 | import static springfox.documentation.schema.AlternateTypeRules.newRule; 32 | 33 | /** 34 | * @author Levin 35 | */ 36 | @SpringBootApplication 37 | @EnableSwagger2 38 | public class AuthorizationApplication { 39 | 40 | public static void main(String[] args) { 41 | SpringApplication.run(AuthorizationApplication.class, args); 42 | } 43 | 44 | private static final String PATH = "/**"; 45 | 46 | private CorsConfiguration buildConfig() { 47 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 48 | corsConfiguration.addAllowedOrigin(CorsConfiguration.ALL); 49 | corsConfiguration.addAllowedHeader(CorsConfiguration.ALL); 50 | corsConfiguration.addAllowedMethod(CorsConfiguration.ALL); 51 | return corsConfiguration; 52 | } 53 | 54 | @Bean 55 | public CorsFilter corsFilter() { 56 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 57 | source.registerCorsConfiguration(PATH, buildConfig()); 58 | return new CorsFilter(source); 59 | } 60 | 61 | @Bean 62 | public Docket petApi() { 63 | return new Docket(DocumentationType.SWAGGER_2) 64 | .select() 65 | .apis(RequestHandlerSelectors.any()) 66 | .paths(PathSelectors.any()) 67 | .build() 68 | .pathMapping("/") 69 | .directModelSubstitute(LocalDate.class, String.class) 70 | .genericModelSubstitutes(ResponseEntity.class) 71 | .alternateTypeRules( 72 | newRule(typeResolver.resolve(DeferredResult.class, 73 | typeResolver.resolve(ResponseEntity.class, WildcardType.class)), 74 | typeResolver.resolve(WildcardType.class))) 75 | .useDefaultResponseMessages(false) 76 | .globalResponseMessage(RequestMethod.GET, 77 | newArrayList(new ResponseMessageBuilder() 78 | .code(500) 79 | .message("500 message") 80 | .responseModel(new ModelRef("Error")) 81 | .build())) 82 | .securitySchemes(newArrayList(apiKey())) 83 | .securityContexts(newArrayList(securityContext())) 84 | ; 85 | } 86 | 87 | @Autowired 88 | private TypeResolver typeResolver; 89 | 90 | private ApiKey apiKey() { 91 | return new ApiKey("X-Authorization", "Authorization", "header"); 92 | } 93 | 94 | private SecurityContext securityContext() { 95 | return SecurityContext.builder() 96 | .securityReferences(defaultAuth()) 97 | .forPaths(PathSelectors.regex("^.*$")) 98 | .build(); 99 | } 100 | 101 | List defaultAuth() { 102 | AuthorizationScope authorizationScope 103 | = new AuthorizationScope("global", "accessEverything"); 104 | AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; 105 | authorizationScopes[0] = authorizationScope; 106 | return newArrayList( 107 | new SecurityReference("X-Authorization", authorizationScopes)); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-authorization/src/main/java/com/battcn/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.battcn.controller; 2 | 3 | import com.battcn.entity.User; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiImplicitParam; 6 | import io.swagger.annotations.ApiImplicitParams; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.web.bind.annotation.*; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | 15 | /** 16 | * swagger 17 | * 18 | * @author Levin 19 | * @since 2018/5/16 0016 20 | */ 21 | @RestController 22 | @RequestMapping("/users") 23 | @Api(tags = "1.1", description = "用户管理", value = "用户管理") 24 | public class UserController { 25 | 26 | private static final Logger log = LoggerFactory.getLogger(UserController.class); 27 | 28 | @GetMapping 29 | @ApiOperation(value = "条件查询(DONE)") 30 | @ApiImplicitParams({ 31 | @ApiImplicitParam(name = "username", value = "用户名", example = "battcn", defaultValue = "default_user"), 32 | @ApiImplicitParam(name = "password", value = "密码", example = "battcn", defaultValue = "default_pass"), 33 | }) 34 | public String query(String username, String password, HttpServletRequest request) { 35 | log.info("Authorization : {}", request.getHeader("Authorization")); 36 | //return new User(1L, username, password); 37 | throw new RuntimeException("111"); 38 | } 39 | 40 | @GetMapping("/{id}") 41 | @ApiOperation(value = "主键查询(DONE)") 42 | @ApiImplicitParams({ 43 | @ApiImplicitParam(name = "id", value = "用户编号"), 44 | }) 45 | public User get(@PathVariable Long id) { 46 | log.info("单个参数用 @ApiImplicitParam"); 47 | return new User(id, "u1", "p1"); 48 | } 49 | 50 | @DeleteMapping("/{id}") 51 | @ApiOperation(value = "删除用户(DONE)") 52 | @ApiImplicitParam(name = "id", value = "用户编号") 53 | public void delete(@PathVariable Long id) { 54 | log.info("单个参数用 ApiImplicitParam"); 55 | } 56 | 57 | @PostMapping 58 | @ApiOperation(value = "添加用户(DONE)") 59 | public User post(@RequestBody User user) { 60 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 61 | return user; 62 | } 63 | 64 | @PutMapping("/{id}") 65 | @ApiOperation(value = "修改用户(DONE)") 66 | public void put(@PathVariable Long id, @RequestBody User user) { 67 | log.info("如果你不想写 @ApiImplicitParam 那么 swagger 也会使用默认的参数名作为描述信息 "); 68 | } 69 | 70 | @PostMapping("/{id}/file") 71 | @ApiOperation(value = "修改用户(DONE)") 72 | public void file(@PathVariable Long id, @RequestParam("file") MultipartFile file) { 73 | log.info(file.getContentType()); 74 | log.info(file.getName()); 75 | log.info(file.getOriginalFilename()); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-authorization/src/main/java/com/battcn/entity/ErrorResponseEntity.java: -------------------------------------------------------------------------------- 1 | package com.battcn.entity; 2 | 3 | /** 4 | * @author Levin 5 | * @version 1.0.1 6 | * @since 2018-01-16 7 | */ 8 | public class ErrorResponseEntity { 9 | 10 | private int customCode; 11 | private String message; 12 | 13 | public int getCustomCode() { 14 | return customCode; 15 | } 16 | 17 | public void setCustomCode(int customCode) { 18 | this.customCode = customCode; 19 | } 20 | 21 | public String getMessage() { 22 | return message; 23 | } 24 | 25 | public void setMessage(String message) { 26 | this.message = message; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-authorization/src/main/java/com/battcn/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.battcn.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Levin 10 | * @since 2018/5/10 0007 11 | */ 12 | @ApiModel 13 | public class User implements Serializable { 14 | 15 | private static final long serialVersionUID = 8655851615465363473L; 16 | 17 | private Long id; 18 | @ApiModelProperty("用户名") 19 | private String username; 20 | @ApiModelProperty("密码") 21 | private String password; 22 | 23 | // TODO 省略get set 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | public void setPassword(String password) { 46 | this.password = password; 47 | } 48 | 49 | public User() { 50 | } 51 | 52 | public User(String username, String password) { 53 | this.username = username; 54 | this.password = password; 55 | } 56 | 57 | public User(Long id, String username, String password) { 58 | this.id = id; 59 | this.username = username; 60 | this.password = password; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "User{" + 66 | "id=" + id + 67 | ", username='" + username + '\'' + 68 | ", password='" + password + '\'' + 69 | '}'; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-authorization/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # \u626B\u63CF\u7684\u5305\u8DEF\u5F84,\u9ED8\u8BA4\u626B\u63CF\u6240\u6709 2 | server.port=8083 3 | spring.swagger.base-package=com.battcn 4 | spring.swagger.enabled=true -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.0.3.RELEASE 9 | 10 | 11 | com.battcn 12 | swagger-spring-boot-sample-basic 13 | 0.0.1-SNAPSHOT 14 | jar 15 | 16 | 17 | UTF-8 18 | UTF-8 19 | 1.8 20 | 21 | 22 | 23 | 24 | 25 | com.alibaba 26 | fastjson 27 | 1.2.47 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | com.battcn 35 | swagger-spring-boot-starter 36 | 2.1.5-RELEASE 37 | 43 | 44 | 49 | 50 | com.battcn 51 | swagger-spring-boot-autoconfigure 52 | 2.1.5-RELEASE 53 | 54 | 55 | com.battcn 56 | swagger-spring-boot-actuator 57 | 2.1.5-RELEASE 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-test 62 | test 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-actuator 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-maven-plugin 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/BasicApplication.java: -------------------------------------------------------------------------------- 1 | package com.swagger; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.web.cors.CorsConfiguration; 8 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 9 | import org.springframework.web.filter.CorsFilter; 10 | 11 | /** 12 | * @author Levin 13 | */ 14 | @SpringBootApplication 15 | public class BasicApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(BasicApplication.class, args); 19 | } 20 | 21 | private static final String PATH = "/**"; 22 | 23 | private CorsConfiguration buildConfig() { 24 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 25 | // 设置你要允许的网站域名,如果全允许则设为 * 26 | corsConfiguration.addAllowedOrigin("http://localhost:8081"); 27 | corsConfiguration.addAllowedOrigin(CorsConfiguration.ALL); 28 | corsConfiguration.addAllowedHeader(CorsConfiguration.ALL); 29 | corsConfiguration.addAllowedMethod(CorsConfiguration.ALL); 30 | corsConfiguration.setAllowCredentials(true); 31 | return corsConfiguration; 32 | } 33 | 34 | @Bean 35 | public FilterRegistrationBean filterRegistrationBean() { 36 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 37 | source.registerCorsConfiguration(PATH, buildConfig()); 38 | source.registerCorsConfiguration("/*", buildConfig()); 39 | FilterRegistrationBean bean = new FilterRegistrationBean<>(new CorsFilter(source)); 40 | // 这个顺序很重要哦,为避免麻烦请设置在最前 41 | bean.setOrder(0); 42 | return bean; 43 | //return new CorsFilter(source); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/order/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.order; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.google.common.collect.Lists; 5 | import com.swagger.entity.order.Order; 6 | import com.swagger.entity.order.OrderLine; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiImplicitParam; 9 | import io.swagger.annotations.ApiImplicitParams; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @author Levin 17 | * @since 2019/2/12 0012 18 | */ 19 | @RestController 20 | @RequestMapping("/orders") 21 | @Api(tags = {"9.0.1"}, description = "订单", value = "订单") 22 | public class OrderController { 23 | 24 | 25 | @GetMapping 26 | @ApiOperation(value = "条件查询(DONE)") 27 | @ApiImplicitParams({ 28 | @ApiImplicitParam(name = "status", value = "状态", example = "111", paramType = "query", defaultValue = "100", allowableValues = "1,2,3,4"), 29 | @ApiImplicitParam(name = "name", value = "姓名", example = "姓名", paramType = "query", required = true), 30 | @ApiImplicitParam(name = "remark", value = "备注", example = "备注", paramType = "query", required = true), 31 | }) 32 | public String query(Integer status, String name, String remark) { 33 | return status + "===" + name + "|||" + remark; 34 | } 35 | 36 | @PostMapping("/add1") 37 | @ApiOperation(value = "测试添加(DONE)") 38 | public Order post(@RequestBody Order order) { 39 | return order; 40 | } 41 | 42 | @PostMapping("/add2") 43 | @ApiOperation(value = "测试添加(DONE)") 44 | public List post(@RequestBody List orders) { 45 | return orders; 46 | } 47 | 48 | @PostMapping("/add3") 49 | @ApiOperation(value = "测试添加(DONE)") 50 | public List post3(@RequestParam String key1, @RequestParam String key2, String key3, String key4, @RequestBody List orders) { 51 | System.out.println("==================key1==================" + key1); 52 | System.out.println("==================key2==================" + key2); 53 | System.out.println("==================key3==================" + key3); 54 | System.out.println("==================key4==================" + key4); 55 | return orders; 56 | } 57 | 58 | 59 | @PutMapping("/{key}/{key1}/a/b/{key2}/add4") 60 | @ApiOperation(value = "测试添加(DONE)") 61 | public List post4(@PathVariable String key, @PathVariable String key1, @PathVariable String key2, String key3, String key4, @RequestBody List orders) { 62 | System.out.println("==================key==================" + key); 63 | System.out.println("==================key1==================" + key1); 64 | System.out.println("==================key2==================" + key2); 65 | System.out.println("==================key3==================" + key3); 66 | System.out.println("==================key4==================" + key4); 67 | return orders; 68 | } 69 | 70 | public static void main(String[] args) { 71 | List orders = Lists.newArrayList(); 72 | Order order = new Order(); 73 | order.setId(1); 74 | order.setCount(10L); 75 | OrderLine line = new OrderLine(); 76 | line.setId(111L); 77 | order.setOrderLines(Lists.newArrayList(line)); 78 | orders.add(order); 79 | System.out.println(JSON.toJSONString(orders)); 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/AllowableValueController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.swagger.entity.AllowableValue; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiImplicitParam; 6 | import io.swagger.annotations.ApiImplicitParams; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | /** 11 | * @author Levin 12 | * @since 2018/12/19 0019 13 | */ 14 | @RestController 15 | @RequestMapping(value = "/allowable_values") 16 | @Api(tags = {"6.0.1"}, value = "AllowableValue", description = "AllowableValue") 17 | public class AllowableValueController { 18 | 19 | 20 | @GetMapping 21 | @ApiOperation(value = "条件查询(DONE)") 22 | @ApiImplicitParams({ 23 | @ApiImplicitParam(name = "status", value = "状态", paramType = "query", defaultValue = "100", allowableValues = ""), 24 | }) 25 | public Integer query(Integer status) { 26 | return status; 27 | } 28 | 29 | @PostMapping 30 | @ApiOperation(value = "测试添加(DONE)") 31 | public AllowableValue post(@RequestBody AllowableValue allowableValue) { 32 | return allowableValue; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/ApiResponseController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.battcn.boot.swagger.annotation.ApiOrder; 4 | import com.google.common.collect.Maps; 5 | import com.google.common.collect.Sets; 6 | import com.swagger.entity.Address; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import io.swagger.annotations.ApiResponse; 10 | import io.swagger.annotations.ApiResponses; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.*; 13 | import org.springframework.web.method.HandlerMethod; 14 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; 15 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 16 | import springfox.documentation.spring.web.DocumentationCache; 17 | 18 | import java.util.Map; 19 | import java.util.Set; 20 | 21 | /** 22 | * @author Levin 23 | * @since 2018/12/3 0003 24 | */ 25 | @ApiOrder(100) 26 | @RestController 27 | @RequestMapping(value = "/api_responses") 28 | @Api(tags = {"3.0.1", "2.0.5"}, value = "注解测试11", description = "注解测试22") 29 | public class ApiResponseController { 30 | 31 | @Autowired 32 | private DocumentationCache documentationCache; 33 | @Autowired 34 | private RequestMappingHandlerMapping requestMappingHandlerMapping; 35 | 36 | @ApiOperation(value = "test1",tags = "A") 37 | @ApiResponses({ 38 | @ApiResponse(code = 200, message = "成功"), 39 | @ApiResponse(code = 204, message = "无数据") 40 | }) 41 | @GetMapping("/test1") 42 | public Set> test1() { 43 | Set> classes = Sets.newLinkedHashSet(); 44 | Map map = requestMappingHandlerMapping.getHandlerMethods(); 45 | for (Map.Entry m : map.entrySet()) { 46 | Map hashMap = Maps.newHashMap(); 47 | HandlerMethod method = m.getValue(); 48 | final Class declaringClass = method.getMethod().getDeclaringClass(); 49 | hashMap.put("className", declaringClass.getSimpleName()); 50 | classes.add(hashMap); 51 | } 52 | return classes; 53 | } 54 | 55 | @ApiOperation(value = "test2",tags = "B") 56 | @ApiResponses({ 57 | @ApiResponse(code = 200, message = "成功"), 58 | @ApiResponse(code = 204, message = "无数据") 59 | }) 60 | @PostMapping("/test2") 61 | public String test2(@RequestParam("name") String name, @RequestBody Address address) { 62 | 63 | return name + address.toString(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/BasicController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.battcn.boot.swagger.annotation.ApiOrder; 4 | import com.swagger.entity.Message; 5 | import io.swagger.annotations.Api; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * swagger 13 | * 14 | * @author Levin 15 | * @since 2018/5/16 0016 16 | */ 17 | @ApiOrder(200) 18 | @RestController 19 | @RequestMapping("/basic") 20 | @Api(description = "测试排序", value = "测试排序",tags = "4.0.7") 21 | public class BasicController { 22 | 23 | 24 | @GetMapping("/1") 25 | public int testPage1() { 26 | 27 | return 100; 28 | } 29 | 30 | @GetMapping("/xxxx") 31 | public Message message(@RequestBody Message message) { 32 | 33 | return message; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/DefaultValueController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.swagger.entity.DefaultPojo; 4 | import io.swagger.annotations.Api; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | /** 8 | * swagger 9 | * 10 | * @author Levin 11 | * @since 2018/5/16 0016 12 | */ 13 | @RestController 14 | @RequestMapping("/defaults") 15 | @Api(tags = "2.0.5", description = "默认值", value = "默认值") 16 | public class DefaultValueController { 17 | 18 | @GetMapping 19 | public DefaultPojo defaultPojo() { 20 | 21 | return new DefaultPojo(); 22 | } 23 | 24 | @GetMapping("/query") 25 | public DefaultPojo query(DefaultPojo pojo) { 26 | 27 | return pojo; 28 | } 29 | 30 | @PostMapping 31 | public DefaultPojo defaultPojo1(@RequestBody DefaultPojo defaultPojo) { 32 | 33 | return defaultPojo; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/FileUploadController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import io.swagger.annotations.Api; 4 | import io.swagger.annotations.ApiOperation; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.web.bind.annotation.*; 8 | import org.springframework.web.multipart.MultipartFile; 9 | 10 | /** 11 | * swagger 12 | * 13 | * @author Levin 14 | * @since 2018/5/16 0016 15 | */ 16 | @RestController 17 | @RequestMapping("/files") 18 | @Api(tags = "2.18", description = "文件上传", value = "文件上传") 19 | public class FileUploadController { 20 | 21 | private static final Logger log = LoggerFactory.getLogger(FileUploadController.class); 22 | 23 | @PostMapping("/{id}/file") 24 | @ApiOperation(value = "文件上传(DONE)") 25 | public String file(@PathVariable Long id, @RequestParam("file") MultipartFile file) { 26 | log.info(file.getContentType()); 27 | log.info(file.getName()); 28 | log.info(file.getOriginalFilename()); 29 | return file.getOriginalFilename(); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/ImageController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.swagger.utils.NewVerifyCodeUtils; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.servlet.ServletOutputStream; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | /** 16 | * @author Levin 17 | * @since 2018/10/8 0008 18 | */ 19 | @RestController 20 | @RequestMapping("/images") 21 | @Api(tags = "2.0.8", description = "图片管理", value = "图片管理") 22 | public class ImageController { 23 | 24 | 25 | @GetMapping("/none") 26 | @ApiOperation(value = "验证码(NONE)") 27 | public void genCaptcha1(HttpServletResponse response) throws IOException { 28 | response.setContentType("image/jpeg"); 29 | response.setHeader("Pragma", "No-cache"); 30 | response.setHeader("Cache-Control", "no-cache"); 31 | response.setDateHeader("Expires", 0); 32 | ServletOutputStream outputStream = response.getOutputStream(); 33 | final String code = NewVerifyCodeUtils.outputNumberVerifyImage(outputStream); 34 | System.out.println(code); 35 | outputStream.flush(); 36 | outputStream.close(); 37 | } 38 | 39 | @GetMapping 40 | @ApiOperation(value = "验证码(NONE)", produces = MediaType.IMAGE_JPEG_VALUE) 41 | public void genCaptcha(HttpServletResponse response) throws IOException { 42 | response.setContentType("image/jpeg"); 43 | response.setHeader("Pragma", "No-cache"); 44 | response.setHeader("Cache-Control", "no-cache"); 45 | response.setDateHeader("Expires", 0); 46 | ServletOutputStream outputStream = response.getOutputStream(); 47 | final String code = NewVerifyCodeUtils.outputNumberVerifyImage(outputStream); 48 | System.out.println(code); 49 | outputStream.flush(); 50 | outputStream.close(); 51 | } 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/JsonController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import io.swagger.annotations.Api; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | /** 8 | * swagger 9 | * 10 | * @author Levin 11 | * @since 2018/5/16 0016 12 | */ 13 | @RestController 14 | @RequestMapping("/json") 15 | @Api(description = "阿里JSON", value = "阿里JSON") 16 | public class JsonController { 17 | 18 | @GetMapping 19 | public String string(String value) { 20 | return value; 21 | } 22 | 23 | @PostMapping("/test1") 24 | public String test1(@RequestBody String object) { 25 | return object; 26 | } 27 | 28 | @PostMapping("/test2") 29 | public JSONObject test2(@RequestBody JSONObject object) { 30 | return object; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/PageController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.swagger.entity.Page; 4 | import com.swagger.entity.User; 5 | import io.swagger.annotations.Api; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | /** 10 | * swagger 11 | * 12 | * @author Levin 13 | * @since 2018/5/16 0016 14 | */ 15 | @RestController 16 | @RequestMapping("/pages") 17 | @Api(description = "分页管理", value = "系统管理") 18 | public class PageController { 19 | 20 | 21 | @PostMapping 22 | public Page testPage(@RequestBody Page page) { 23 | 24 | return page; 25 | } 26 | 27 | @PostMapping("/users") 28 | @ApiOperation(value = "测试双POST(DONE)",notes = "测试一下notes属性") 29 | public User post(@RequestBody User user) { 30 | return user; 31 | } 32 | 33 | @GetMapping("/1") 34 | public int testPage1() { 35 | 36 | return 100; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/other/TreeController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.other; 2 | 3 | import com.swagger.entity.PojoA; 4 | import com.swagger.entity.PojoC; 5 | import com.swagger.entity.TreeNode; 6 | import io.swagger.annotations.Api; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * swagger 13 | * 14 | * @author Levin 15 | * @since 2018/5/16 0016 16 | */ 17 | @RestController 18 | @RequestMapping("/trees") 19 | @Api(tags = "2.5", description = "数型结构", value = "数型结构") 20 | public class TreeController { 21 | 22 | @GetMapping 23 | public TreeNode tree() { 24 | 25 | return new TreeNode(); 26 | } 27 | 28 | @GetMapping("/test2") 29 | public PojoA test2() { 30 | return new PojoA(); 31 | } 32 | 33 | 34 | @GetMapping("/test3") 35 | public PojoC test3() { 36 | return new PojoC(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/controller/user/UserController.java: -------------------------------------------------------------------------------- 1 | package com.swagger.controller.user; 2 | 3 | import com.battcn.boot.swagger.model.DataType; 4 | import com.battcn.boot.swagger.model.ParamType; 5 | import com.swagger.entity.User; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiImplicitParam; 8 | import io.swagger.annotations.ApiImplicitParams; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.web.bind.annotation.*; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * swagger 19 | * 20 | * @author Levin 21 | * @since 2018/5/16 0016 22 | */ 23 | @RestController 24 | @RequestMapping("/users") 25 | @Api(tags = "2.0.11", description = "用户管理", value = "用户管理") 26 | public class UserController { 27 | 28 | private static final Logger log = LoggerFactory.getLogger(UserController.class); 29 | 30 | @GetMapping 31 | @ApiOperation(value = "条件查询(DONE)",notes = "测试一下notes属性") 32 | @ApiImplicitParams({ 33 | @ApiImplicitParam(name = "username", value = "用户名", dataType = DataType.STRING, paramType = ParamType.QUERY,defaultValue = "username111"), 34 | @ApiImplicitParam(name = "password", value = "密码", dataType = DataType.STRING, paramType = ParamType.QUERY), 35 | }) 36 | public User query(String username, String password) { 37 | log.info("多个参数用 @ApiImplicitParams"); 38 | //return new User(1L, username, password); 39 | throw new RuntimeException("服务器异常..2019-03-18 15:12:11.306 ERROR 17128 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: 服务器异常...] with root cause\n."); 40 | } 41 | 42 | @GetMapping("/{id}") 43 | @ApiOperation(value = "主键查询(DONE)",notes = "测试一下notes属性") 44 | @ApiImplicitParams({ 45 | @ApiImplicitParam(name = "id", value = "用户编号", dataType = DataType.LONG, paramType = ParamType.PATH), 46 | }) 47 | public User get(@PathVariable Long id) { 48 | log.info("单个参数用 @ApiImplicitParam"); 49 | return new User(id, "u1", "p1"); 50 | } 51 | 52 | @DeleteMapping("/{id}") 53 | @ApiOperation(value = "删除用户(DONE)",notes = "测试一下notes属性111") 54 | @ApiImplicitParam(name = "id", value = "用户编号", dataType = DataType.LONG, paramType = ParamType.PATH) 55 | public void delete(@PathVariable Long id) { 56 | log.info("单个参数用 ApiImplicitParam"); 57 | } 58 | 59 | @PostMapping 60 | @ApiOperation(value = "添加用户(DONE)") 61 | public User post(@RequestBody User user) { 62 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 63 | return user; 64 | } 65 | 66 | @PostMapping("/multipar") 67 | @ApiOperation(value = "添加用户(DONE)") 68 | public List multipar(@RequestBody List user) { 69 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 70 | 71 | return user; 72 | } 73 | 74 | @PostMapping("/array") 75 | @ApiOperation(value = "添加用户(DONE)") 76 | public User[] array(@RequestBody User[] user) { 77 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 78 | return user; 79 | } 80 | 81 | @PostMapping("/multipar2") 82 | @ApiOperation(value = "添加用户(DONE)") 83 | public List multipar2(@RequestBody List user) { 84 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 85 | 86 | return user; 87 | } 88 | 89 | @PostMapping("/array2") 90 | @ApiOperation(value = "添加用户(DONE)") 91 | public User[] array2(@RequestBody User[] user) { 92 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 93 | return user; 94 | } 95 | 96 | 97 | @PutMapping("/{id}") 98 | @ApiOperation(value = "修改用户(DONE)") 99 | public void put(@PathVariable Long id, @RequestBody User user) { 100 | log.info("如果你不想写 @ApiImplicitParam 那么 swagger 也会使用默认的参数名作为描述信息 "); 101 | } 102 | 103 | @PostMapping("/{id}/file") 104 | @ApiOperation(value = "文件上传(DONE)") 105 | public String file(@PathVariable Long id, @RequestParam("file") MultipartFile file) { 106 | log.info(file.getContentType()); 107 | log.info(file.getName()); 108 | log.info(file.getOriginalFilename()); 109 | return file.getOriginalFilename(); 110 | } 111 | 112 | 113 | } 114 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/Address.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel 7 | public class Address { 8 | 9 | @ApiModelProperty(required = true,value = "ID啊") 10 | private int id; 11 | private String address; 12 | 13 | public int getId() { 14 | return id; 15 | } 16 | 17 | public void setId(int id) { 18 | this.id = id; 19 | } 20 | 21 | public String getAddress() { 22 | return address; 23 | } 24 | 25 | public void setAddress(String address) { 26 | this.address = address; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Address{" + 32 | "id=" + id + 33 | ", address='" + address + '\'' + 34 | '}'; 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/AllowableValue.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | /** 7 | * @author Levin 8 | * @since 2018/12/19 0019 9 | */ 10 | @ApiModel 11 | public class AllowableValue { 12 | 13 | private Long id; 14 | @ApiModelProperty(value = "状态码", allowableValues = "1,2,3,4") 15 | private Integer status; 16 | @ApiModelProperty(value = "名字", allowableValues = "小明") 17 | private String name; 18 | 19 | public Long getId() { 20 | return id; 21 | } 22 | 23 | public void setId(Long id) { 24 | this.id = id; 25 | } 26 | 27 | public Integer getStatus() { 28 | return status; 29 | } 30 | 31 | public void setStatus(Integer status) { 32 | this.status = status; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/DefaultPojo.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel 7 | public class DefaultPojo { 8 | 9 | @ApiModelProperty(value = "ID",example = "1000") 10 | private int id; 11 | @ApiModelProperty(value = "地址",example = "上海") 12 | private String address; 13 | 14 | public int getId() { 15 | return id; 16 | } 17 | 18 | public void setId(int id) { 19 | this.id = id; 20 | } 21 | 22 | public String getAddress() { 23 | return address; 24 | } 25 | 26 | public void setAddress(String address) { 27 | this.address = address; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/Message.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | @ApiModel(description = "描述消息") 7 | public class Message { 8 | 9 | @ApiModelProperty(value = "消息啊", required = true) 10 | private String msg; 11 | 12 | public String getMsg() { 13 | return msg; 14 | } 15 | 16 | public void setMsg(String msg) { 17 | this.msg = msg; 18 | } 19 | 20 | public Message() { 21 | } 22 | 23 | public Message(String msg) { 24 | this.msg = msg; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/Page.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | /** 7 | * @author Levin 8 | * @since 2018/8/6 0006 9 | */ 10 | @ApiModel 11 | public class Page { 12 | 13 | @ApiModelProperty(required = true) 14 | private Integer page; 15 | @ApiModelProperty(required = false) 16 | private Integer pageSize; 17 | 18 | public Integer getPage() { 19 | return page; 20 | } 21 | 22 | public void setPage(Integer page) { 23 | this.page = page; 24 | } 25 | 26 | public Integer getPageSize() { 27 | return pageSize; 28 | } 29 | 30 | public void setPageSize(Integer pageSize) { 31 | this.pageSize = pageSize; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/PojoA.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | /** 7 | * @author Levin 8 | * @since 2018/10/17 0017 9 | */ 10 | @ApiModel(description = "pojoA对象") 11 | public class PojoA { 12 | 13 | @ApiModelProperty("ID") 14 | private long id; 15 | @ApiModelProperty("邮箱") 16 | private String email; 17 | @ApiModelProperty("pojoB对象") 18 | private PojoB pojoB; 19 | 20 | public long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getEmail() { 29 | return email; 30 | } 31 | 32 | public void setEmail(String email) { 33 | this.email = email; 34 | } 35 | 36 | public PojoB getPojoB() { 37 | return pojoB; 38 | } 39 | 40 | public void setPojoB(PojoB pojoB) { 41 | this.pojoB = pojoB; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/PojoB.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | 5 | /** 6 | * @author Levin 7 | * @since 2018/10/17 0017 8 | */ 9 | @ApiModel(description = "class pojoB对象") 10 | public class PojoB { 11 | 12 | private long id; 13 | private String address; 14 | private PojoA pojoA; 15 | 16 | public long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getAddress() { 25 | return address; 26 | } 27 | 28 | public void setAddress(String address) { 29 | this.address = address; 30 | } 31 | 32 | public PojoA getPojoA() { 33 | return pojoA; 34 | } 35 | 36 | public void setPojoA(PojoA pojoA) { 37 | this.pojoA = pojoA; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/PojoC.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | /** 4 | * @author Levin 5 | * @since 2018/10/17 0017 6 | */ 7 | public class PojoC { 8 | 9 | private long id; 10 | private String address; 11 | private PojoD pojoD; 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getAddress() { 22 | return address; 23 | } 24 | 25 | public void setAddress(String address) { 26 | this.address = address; 27 | } 28 | 29 | public PojoD getPojoD() { 30 | return pojoD; 31 | } 32 | 33 | public void setPojoD(PojoD pojoD) { 34 | this.pojoD = pojoD; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/PojoD.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | /** 4 | * @author Levin 5 | * @since 2018/10/17 0017 6 | */ 7 | public class PojoD { 8 | 9 | private long id; 10 | private String address; 11 | private PojoE pojoE; 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getAddress() { 22 | return address; 23 | } 24 | 25 | public void setAddress(String address) { 26 | this.address = address; 27 | } 28 | 29 | public PojoE getPojoE() { 30 | return pojoE; 31 | } 32 | 33 | public void setPojoE(PojoE pojoE) { 34 | this.pojoE = pojoE; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/PojoE.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | /** 4 | * @author Levin 5 | * @since 2018/10/17 0017 6 | */ 7 | public class PojoE { 8 | 9 | private long id; 10 | private String address; 11 | private PojoE pojoE; 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getAddress() { 22 | return address; 23 | } 24 | 25 | public void setAddress(String address) { 26 | this.address = address; 27 | } 28 | 29 | public PojoE getPojoE() { 30 | return pojoE; 31 | } 32 | 33 | public void setPojoE(PojoE pojoE) { 34 | this.pojoE = pojoE; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/TreeNode.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Levin 10 | * @since 2018/10/12 0012 11 | */ 12 | @ApiModel 13 | public class TreeNode { 14 | 15 | @ApiModelProperty("ID") 16 | private Integer id; 17 | @ApiModelProperty("节点名字") 18 | private String name; 19 | private List testTreeNodes; 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public List getTestTreeNodes() { 38 | return testTreeNodes; 39 | } 40 | 41 | public void setTestTreeNodes(List testTreeNodes) { 42 | this.testTreeNodes = testTreeNodes; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.io.Serializable; 7 | import java.math.BigDecimal; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Levin 12 | * @since 2018/5/10 0007 13 | */ 14 | @ApiModel 15 | public class User implements Serializable { 16 | 17 | private static final long serialVersionUID = 8655851615465363473L; 18 | 19 | private Long id; 20 | @ApiModelProperty(value = "用户名", required = false) 21 | private String username; 22 | @ApiModelProperty(value = "密码", required = true) 23 | private String password; 24 | @ApiModelProperty(value = "List消息", required = true) 25 | private List messages; 26 | 27 | @ApiModelProperty("测试属性") 28 | private BigDecimal price; 29 | @ApiModelProperty("测试地址") 30 | private Address address; 31 | 32 | // TODO 省略get set 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getUsername() { 43 | return username; 44 | } 45 | 46 | public void setUsername(String username) { 47 | this.username = username; 48 | } 49 | 50 | public String getPassword() { 51 | return password; 52 | } 53 | 54 | public void setPassword(String password) { 55 | this.password = password; 56 | } 57 | 58 | 59 | public Address getAddress() { 60 | return address; 61 | } 62 | 63 | public void setAddress(Address address) { 64 | this.address = address; 65 | } 66 | 67 | public List getMessages() { 68 | return messages; 69 | } 70 | 71 | public void setMessages(List messages) { 72 | this.messages = messages; 73 | } 74 | 75 | public User() { 76 | } 77 | 78 | public User(String username, String password) { 79 | this.username = username; 80 | this.password = password; 81 | } 82 | 83 | public User(Long id, String username, String password) { 84 | this.id = id; 85 | this.username = username; 86 | this.password = password; 87 | } 88 | 89 | public BigDecimal getPrice() { 90 | return price; 91 | } 92 | 93 | public void setPrice(BigDecimal price) { 94 | this.price = price; 95 | } 96 | 97 | @Override 98 | public String toString() { 99 | return "User{" + 100 | "id=" + id + 101 | ", username='" + username + '\'' + 102 | ", password='" + password + '\'' + 103 | '}'; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/order/Order.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity.order; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.math.BigDecimal; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Levin 11 | * @since 2019/2/12 0012 12 | */ 13 | @ApiModel(description = "订单类") 14 | public class Order { 15 | 16 | @ApiModelProperty(value = "ID") 17 | private int id; 18 | @ApiModelProperty("价格") 19 | private BigDecimal price; 20 | @ApiModelProperty("库存") 21 | private Long count; 22 | @ApiModelProperty(value = "描述", allowEmptyValue = true) 23 | private String desc; 24 | @ApiModelProperty(value = "状态码", allowableValues = "1,2,3,4") 25 | private Integer status; 26 | @ApiModelProperty(value = "名字", allowableValues = "测试商品") 27 | private String remark; 28 | 29 | 30 | @ApiModelProperty(required = true, value = "订单行") 31 | private List orderLines; 32 | 33 | 34 | public int getId() { 35 | return id; 36 | } 37 | 38 | public void setId(int id) { 39 | this.id = id; 40 | } 41 | 42 | public BigDecimal getPrice() { 43 | return price; 44 | } 45 | 46 | public void setPrice(BigDecimal price) { 47 | this.price = price; 48 | } 49 | 50 | public Long getCount() { 51 | return count; 52 | } 53 | 54 | public void setCount(Long count) { 55 | this.count = count; 56 | } 57 | 58 | public String getDesc() { 59 | return desc; 60 | } 61 | 62 | public void setDesc(String desc) { 63 | this.desc = desc; 64 | } 65 | 66 | public Integer getStatus() { 67 | return status; 68 | } 69 | 70 | public void setStatus(Integer status) { 71 | this.status = status; 72 | } 73 | 74 | public String getRemark() { 75 | return remark; 76 | } 77 | 78 | public void setRemark(String remark) { 79 | this.remark = remark; 80 | } 81 | 82 | public List getOrderLines() { 83 | return orderLines; 84 | } 85 | 86 | public void setOrderLines(List orderLines) { 87 | this.orderLines = orderLines; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/entity/order/OrderLine.java: -------------------------------------------------------------------------------- 1 | package com.swagger.entity.order; 2 | 3 | import com.swagger.entity.Address; 4 | import com.swagger.entity.Message; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | 8 | import java.math.BigDecimal; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Levin 13 | * @since 2019/2/12 0012 14 | */ 15 | @ApiModel(description = "订单行项") 16 | public class OrderLine { 17 | 18 | @ApiModelProperty(value = "ID") 19 | private long id; 20 | @ApiModelProperty(value = "名字", allowableValues = "衣服") 21 | private String name; 22 | @ApiModelProperty("收货地址") 23 | private List

addresses; 24 | @ApiModelProperty(value = "订单标签", allowableValues = "奔驰,宝马") 25 | private List tags; 26 | 27 | private Message message; 28 | 29 | 30 | public long getId() { 31 | return id; 32 | } 33 | 34 | public void setId(long id) { 35 | this.id = id; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public List
getAddresses() { 47 | return addresses; 48 | } 49 | 50 | public void setAddresses(List
addresses) { 51 | this.addresses = addresses; 52 | } 53 | 54 | public List getTags() { 55 | return tags; 56 | } 57 | 58 | public void setTags(List tags) { 59 | this.tags = tags; 60 | } 61 | 62 | public Message getMessage() { 63 | return message; 64 | } 65 | 66 | public void setMessage(Message message) { 67 | this.message = message; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/java/com/swagger/utils/NewVerifyCodeUtils.java: -------------------------------------------------------------------------------- 1 | package com.swagger.utils; 2 | 3 | import javax.imageio.ImageIO; 4 | import java.awt.*; 5 | import java.awt.image.BufferedImage; 6 | import java.io.File; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.io.OutputStream; 10 | import java.util.Arrays; 11 | import java.util.Random; 12 | 13 | /** 14 | * 图片验证码生成 15 | * 16 | * @author Levin 17 | */ 18 | public class NewVerifyCodeUtils { 19 | 20 | /** 21 | * 使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符 22 | */ 23 | private static final String DEFAULT_STRING_VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"; 24 | private static final String DEFAULT_NUMBER_VERIFY_CODES = "0123456789"; 25 | private static final String FORMAT_NAME = "png"; 26 | private static final String FONT_NAME = "Courier"; 27 | private static final int DEFAULT_WIDTH = 200; 28 | private static final int DEFAULT_HEIGHT = 80; 29 | private static final int DEFAULT_VERIFY_LENGTH = 4; 30 | private static Random random = new Random(); 31 | 32 | 33 | /** 34 | * 使用系统默认字符源生成验证码 35 | * 36 | * @param verifySize 验证码长度 37 | * @return 字符验证码 38 | */ 39 | public static String generateStringCode(int verifySize) { 40 | return generateVerifyCode(verifySize, DEFAULT_STRING_VERIFY_CODES); 41 | } 42 | 43 | /** 44 | * 使用指定源生成验证码 45 | * 46 | * @param verifySize 验证码长度 47 | * @param sources 验证码字符源 48 | * @return 字符验证码 49 | */ 50 | public static String generateVerifyCode(int verifySize, String sources) { 51 | if (sources == null || sources.length() == 0) { 52 | sources = DEFAULT_STRING_VERIFY_CODES; 53 | } 54 | int codesLen = sources.length(); 55 | Random rand = new Random(System.currentTimeMillis()); 56 | StringBuilder verifyCode = new StringBuilder(verifySize); 57 | for (int i = 0; i < verifySize; i++) { 58 | verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1))); 59 | } 60 | return verifyCode.toString(); 61 | } 62 | 63 | /** 64 | * 生成随机验证码文件,并返回验证码值 65 | * 66 | * @param width 宽度 67 | * @param height 高度 68 | * @param outputFile 输出路径 69 | * @param verifySize 字符长度 70 | * @return 验证码 71 | * @throws IOException IOException 72 | */ 73 | public static String outputVerifyImage(int width, int height, File outputFile, int verifySize) throws IOException { 74 | String verifyCode = generateStringCode(verifySize); 75 | outputImage(width, height, outputFile, verifyCode); 76 | return verifyCode; 77 | } 78 | 79 | /** 80 | * 输出随机验证码图片流,并返回验证码值 81 | * 82 | * @param width 宽度 83 | * @param height 高度 84 | * @param os 输出流 85 | * @param verifySize 字符长度 86 | * @return 验证码 87 | * @throws IOException IOException 88 | */ 89 | public static String outputStringVerifyImage(int width, int height, OutputStream os, int verifySize) throws IOException { 90 | String verifyCode = generateStringCode(verifySize); 91 | outputImage(width, height, os, verifyCode); 92 | return verifyCode; 93 | } 94 | 95 | public static String outputNumberVerifyImage(OutputStream os) throws IOException { 96 | String verifyCode = generateVerifyCode(DEFAULT_VERIFY_LENGTH, DEFAULT_NUMBER_VERIFY_CODES); 97 | outputImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, os, verifyCode); 98 | return verifyCode; 99 | } 100 | 101 | /** 102 | * 生成指定验证码图像文件 103 | * 104 | * @param width 宽度 105 | * @param height 高度 106 | * @param outputFile 输出文件 107 | * @param code 指定验证码 108 | * @throws IOException IOException 109 | */ 110 | public static void outputImage(int width, int height, File outputFile, String code) throws IOException { 111 | if (outputFile == null) { 112 | return; 113 | } 114 | File dir = outputFile.getParentFile(); 115 | if (!dir.exists()) { 116 | dir.mkdirs(); 117 | } 118 | try { 119 | outputFile.createNewFile(); 120 | FileOutputStream fos = new FileOutputStream(outputFile); 121 | outputImage(width, height, fos, code); 122 | fos.close(); 123 | } catch (IOException e) { 124 | throw e; 125 | } 126 | } 127 | 128 | private static final int LINE_SIZE = 20; 129 | 130 | /** 131 | * 输出指定验证码图片流 132 | * 133 | * @param width 宽度 134 | * @param height 高度 135 | * @param os 输出流 136 | * @param code 指定验证码 137 | * @throws IOException IOException 138 | */ 139 | public static void outputImage(int width, int height, OutputStream os, String code) throws IOException { 140 | int verifySize = code.length(); 141 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 142 | Random rand = new Random(); 143 | Graphics2D g2 = image.createGraphics(); 144 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 145 | Color[] colors = new Color[5]; 146 | Color[] colorSpaces = new Color[]{Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, 147 | Color.ORANGE, Color.PINK, Color.YELLOW}; 148 | float[] fractions = new float[colors.length]; 149 | for (int i = 0; i < colors.length; i++) { 150 | colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)]; 151 | fractions[i] = rand.nextFloat(); 152 | } 153 | Arrays.sort(fractions); 154 | // 设置边框色 155 | g2.setColor(Color.GRAY); 156 | g2.fillRect(0, 0, width, height); 157 | 158 | Color c = getRandColor(200, 250); 159 | // 设置背景色 160 | g2.setColor(c); 161 | g2.fillRect(0, 2, width, height - 4); 162 | 163 | // 设置背景色 164 | g2.setBackground(Color.WHITE); 165 | g2.setColor(new Color(0, 191, 255)); 166 | int fontSize = height - 5; 167 | //LAYOUT_NO_LIMIT_CONTEXT 168 | Font font = new Font(FONT_NAME, Font.PLAIN, fontSize); 169 | g2.setFont(font); 170 | char[] chars = code.toCharArray(); 171 | for (int i = 0; i < verifySize; i++) { 172 | g2.drawChars(chars, i, 1, ((width - 10) / verifySize) * i + 5, height / 2 + fontSize / 2 - 5); 173 | } 174 | // 绘制干扰线 175 | Random random = new Random(); 176 | // 设置线条的颜色 177 | g2.setColor(getRandColor(160, 200)); 178 | for (int i = 0; i < LINE_SIZE; i++) { 179 | int x = random.nextInt(width - 1); 180 | int y = random.nextInt(height - 1); 181 | int xl = random.nextInt(6) + 1; 182 | int yl = random.nextInt(12) + 1; 183 | g2.drawLine(x, y, x + xl + 40, y + yl + 20); 184 | } 185 | 186 | // 添加噪点 // 噪声率 187 | float yawpRate = 0.15f; 188 | int area = (int) (yawpRate * width * height); 189 | for (int i = 0; i < area; i++) { 190 | int x = random.nextInt(width); 191 | int y = random.nextInt(height); 192 | int rgb = getRandomIntColor(); 193 | image.setRGB(x, y, rgb); 194 | } 195 | g2.dispose(); 196 | ImageIO.write(image, FORMAT_NAME, os); 197 | } 198 | 199 | private static final int TRICOLOR_MAX_SIZE = 255; 200 | 201 | private static Color getRandColor(int fc, int bc) { 202 | if (fc > TRICOLOR_MAX_SIZE) { 203 | fc = TRICOLOR_MAX_SIZE; 204 | } 205 | if (bc > TRICOLOR_MAX_SIZE) { 206 | bc = TRICOLOR_MAX_SIZE; 207 | } 208 | int r = fc + random.nextInt(bc - fc); 209 | int g = fc + random.nextInt(bc - fc); 210 | int b = fc + random.nextInt(bc - fc); 211 | return new Color(r, g, b); 212 | } 213 | 214 | private static int getRandomIntColor() { 215 | int[] rgb = getRandomRgb(); 216 | int color = 0; 217 | for (int c : rgb) { 218 | color = color << 8; 219 | color = color | c; 220 | } 221 | return color; 222 | } 223 | 224 | private static final int RANDOM_SIZE = 3; 225 | 226 | private static int[] getRandomRgb() { 227 | int[] rgb = new int[RANDOM_SIZE]; 228 | for (int i = 0; i < RANDOM_SIZE; i++) { 229 | rgb[i] = random.nextInt(255); 230 | } 231 | return rgb; 232 | } 233 | 234 | private static void shear(Graphics g, int w1, int h1, Color color) { 235 | shearX(g, w1, h1, color); 236 | shearY(g, w1, h1, color); 237 | } 238 | 239 | private static void shearX(Graphics g, int w1, int h1, Color color) { 240 | int period = random.nextInt(2); 241 | int frames = 1; 242 | int phase = random.nextInt(2); 243 | for (int i = 0; i < h1; i++) { 244 | double d = (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * phase) / frames); 245 | g.copyArea(0, i, w1, 1, (int) d, 0); 246 | g.setColor(color); 247 | g.drawLine((int) d, i, 0, i); 248 | g.drawLine((int) d + w1, i, w1, i); 249 | } 250 | } 251 | 252 | private static void shearY(Graphics graphics, int width, int height, Color color) { 253 | // 50; 254 | int period = random.nextInt(40) + 10; 255 | int frames = 20; 256 | int phase = 7; 257 | for (int i = 0; i < width; i++) { 258 | double d = (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * phase) / frames); 259 | graphics.copyArea(i, 0, 1, height, 0, (int) d); 260 | graphics.setColor(color); 261 | graphics.drawLine(i, (int) d, i, 0); 262 | graphics.drawLine(i, (int) d + height, i, height); 263 | } 264 | } 265 | 266 | public static void main(String[] args) throws IOException { 267 | File dir = new File("D:/img_data"); 268 | int width = 200, height = 80; 269 | String verifyCode = generateVerifyCode(4, "0123456789"); 270 | File file = new File(dir, verifyCode + ".png"); 271 | outputImage(width, height, file, verifyCode); 272 | //NewVerifyCodeUtils.outputImage(116, 43, os, verifyCode); 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | 3 | # \u626B\u63CF\u7684\u5305\u8DEF\u5F84,\u9ED8\u8BA4\u626B\u63CF\u6240\u6709 4 | 5 | spring.swagger.base-package=com.swagger 6 | spring.swagger.enabled=true 7 | 8 | spring.swagger.title=\u6807\u9898 9 | spring.swagger.description=\u63CF\u8FF0\u4FE1\u606F 10 | spring.swagger.version=\u7248\u672C 11 | spring.swagger.license=\u8BB8\u53EF\u8BC1 12 | spring.swagger.licenseUrl=\u8BB8\u53EF\u8BC1URL 13 | spring.swagger.host=http://localhost:${server.port}/swagger-ui.html 14 | spring.swagger.termsOfServiceUrl=\u670D\u52A1\u6761\u6B3EURL 15 | spring.swagger.contact.name=Levin 16 | spring.swagger.contact.url=http://localhost:${server.port}/swagger-ui.html 17 | spring.swagger.contact.email=1837307557@qq.com 18 | 19 | spring.swagger.api-key.key-name=myToken 20 | # \u4E2D\u6587\u5206\u7EC4\u9700\u8981\u8F6C\u6362\u6210 ASCII 21 | spring.swagger.groups[\u7528\u6237].basePackage=com.swagger.controller.user 22 | spring.swagger.groups[\u8BA2\u5355].basePackage=com.swagger.controller.order 23 | spring.swagger.groups[\u5176\u5B83].basePackage=com.swagger.controller.other 24 | 25 | # \u5173\u95ED JSR 26 | spring.swagger.validator-plugin=false 27 | spring.swagger.global-response-messages.POST[0].code=400 28 | spring.swagger.global-response-messages.POST[0].message=server response 400 29 | spring.swagger.global-response-messages.POST[1].code=404 30 | spring.swagger.global-response-messages.POST[1].message=server response 404 31 | #server.servlet.context-path=/project 32 | spring.swagger.security.filter-plugin=false 33 | spring.swagger.security.username=battcn 34 | spring.swagger.security.password=battcn -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-basic/src/main/resources/bak_application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | swagger: 3 | enabled: true 4 | title: 标题 5 | description: 描述信息 6 | version: 系统版本号 7 | contact: 8 | name: 维护者信息 9 | base-package: com.swagger 10 | #全局参数,比如Token之类的验证信息可以全局话配置 11 | global-operation-parameters: 12 | - description: 'Token信息,必填项' 13 | modelRef: 'string' 14 | name: 'Authorization' 15 | parameter-type: 'header' 16 | required: true 17 | global-response-messages: 18 | POST[0]: 19 | code: 400 20 | message: 出错啦. 21 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.0.3.RELEASE 9 | 10 | 11 | com.battcn 12 | swagger-spring-boot-sample-group 13 | 0.0.1-SNAPSHOT 14 | jar 15 | 16 | 17 | UTF-8 18 | UTF-8 19 | 1.8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | com.battcn 29 | swagger-spring-boot-starter 30 | 2.1.5-RELEASE 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/java/com/battcn/GroupApplication.java: -------------------------------------------------------------------------------- 1 | package com.battcn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.cors.CorsConfiguration; 7 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 8 | import org.springframework.web.filter.CorsFilter; 9 | 10 | /** 11 | * @author Levin 12 | */ 13 | @SpringBootApplication 14 | public class GroupApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(GroupApplication.class, args); 18 | } 19 | 20 | private static final String PATH = "/**"; 21 | private CorsConfiguration buildConfig() { 22 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 23 | corsConfiguration.addAllowedOrigin(CorsConfiguration.ALL); 24 | corsConfiguration.addAllowedHeader(CorsConfiguration.ALL); 25 | corsConfiguration.addAllowedMethod(CorsConfiguration.ALL); 26 | return corsConfiguration; 27 | } 28 | 29 | @Bean 30 | public CorsFilter corsFilter() { 31 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 32 | source.registerCorsConfiguration(PATH, buildConfig()); 33 | return new CorsFilter(source); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/java/com/battcn/controller/book/BookController.java: -------------------------------------------------------------------------------- 1 | package com.battcn.controller.book; 2 | 3 | import com.battcn.boot.swagger.model.DataType; 4 | import com.battcn.boot.swagger.model.ParamType; 5 | import com.battcn.entity.Book; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiImplicitParam; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | /** 14 | * swagger 15 | * 16 | * @author Levin 17 | * @since 2018/5/16 0016 18 | */ 19 | @RestController 20 | @RequestMapping("/books") 21 | @Api(tags = "1.2", description = "书籍管理", value = "书籍管理") 22 | public class BookController { 23 | 24 | private static final Logger log = LoggerFactory.getLogger(BookController.class); 25 | 26 | @GetMapping 27 | @ApiOperation(value = "条件查询(DONE)") 28 | public Book query(String name) { 29 | log.info("query books by name : {}", name); 30 | return new Book(1L, name); 31 | } 32 | 33 | @DeleteMapping("/{id}") 34 | @ApiOperation(value = "删除用户(DONE)") 35 | @ApiImplicitParam(name = "id", value = "用户编号", dataType = DataType.LONG, paramType = ParamType.PATH) 36 | public void delete(@PathVariable Long id) { 37 | 38 | log.info(" delete books by id : {}", id); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/java/com/battcn/controller/user/UserController.java: -------------------------------------------------------------------------------- 1 | package com.battcn.controller.user; 2 | 3 | import com.battcn.boot.swagger.model.DataType; 4 | import com.battcn.boot.swagger.model.ParamType; 5 | import com.battcn.entity.User; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiImplicitParam; 8 | import io.swagger.annotations.ApiImplicitParams; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * swagger 16 | * 17 | * @author Levin 18 | * @since 2018/5/16 0016 19 | */ 20 | @RestController 21 | @RequestMapping("/users") 22 | @Api(tags = "1.1", description = "用户管理", value = "用户管理") 23 | public class UserController { 24 | 25 | private static final Logger log = LoggerFactory.getLogger(UserController.class); 26 | 27 | @GetMapping 28 | @ApiOperation(value = "条件查询(DONE)") 29 | @ApiImplicitParams({ 30 | @ApiImplicitParam(name = "username", value = "用户名", dataType = DataType.STRING, paramType = ParamType.QUERY), 31 | @ApiImplicitParam(name = "password", value = "密码", dataType = DataType.STRING, paramType = ParamType.QUERY), 32 | }) 33 | public User query(String username, String password) { 34 | log.info("多个参数用 @ApiImplicitParams"); 35 | return new User(1L, username, password); 36 | } 37 | 38 | @GetMapping("/{id}") 39 | @ApiOperation(value = "主键查询(DONE)") 40 | @ApiImplicitParams({ 41 | @ApiImplicitParam(name = "id", value = "用户编号", dataType = DataType.LONG, paramType = ParamType.PATH), 42 | }) 43 | public User get(@PathVariable Long id) { 44 | log.info("单个参数用 @ApiImplicitParam"); 45 | return new User(id, "u1", "p1"); 46 | } 47 | 48 | @DeleteMapping("/{id}") 49 | @ApiOperation(value = "删除用户(DONE)") 50 | @ApiImplicitParam(name = "id", value = "用户编号", dataType = DataType.LONG, paramType = ParamType.PATH) 51 | public void delete(@PathVariable Long id) { 52 | log.info("单个参数用 ApiImplicitParam"); 53 | } 54 | 55 | @PostMapping 56 | @ApiOperation(value = "添加用户(DONE)") 57 | public User post(@RequestBody User user) { 58 | log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam"); 59 | return user; 60 | } 61 | 62 | @PutMapping("/{id}") 63 | @ApiOperation(value = "修改用户(DONE)") 64 | public void put(@PathVariable Long id, @RequestBody User user) { 65 | log.info("如果你不想写 @ApiImplicitParam 那么 swagger 也会使用默认的参数名作为描述信息 "); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/java/com/battcn/entity/Book.java: -------------------------------------------------------------------------------- 1 | package com.battcn.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Levin 10 | * @since 2018/5/10 0007 11 | */ 12 | @ApiModel 13 | public class Book implements Serializable { 14 | 15 | private static final long serialVersionUID = 8655851615465363473L; 16 | 17 | private Long id; 18 | @ApiModelProperty("书籍名称") 19 | private String name; 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | public Book(){} 37 | public Book(Long id, String name) { 38 | this.id = id; 39 | this.name = name; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Book{" + 45 | "id=" + id + 46 | ", name='" + name + '\'' + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/java/com/battcn/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.battcn.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Levin 10 | * @since 2018/5/10 0007 11 | */ 12 | @ApiModel 13 | public class User implements Serializable { 14 | 15 | private static final long serialVersionUID = 8655851615465363473L; 16 | 17 | private Long id; 18 | @ApiModelProperty("用户名") 19 | private String username; 20 | @ApiModelProperty("密码") 21 | private String password; 22 | 23 | // TODO 省略get set 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | public void setPassword(String password) { 46 | this.password = password; 47 | } 48 | 49 | public User() { 50 | } 51 | 52 | public User(String username, String password) { 53 | this.username = username; 54 | this.password = password; 55 | } 56 | 57 | public User(Long id, String username, String password) { 58 | this.id = id; 59 | this.username = username; 60 | this.password = password; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return "User{" + 66 | "id=" + id + 67 | ", username='" + username + '\'' + 68 | ", password='" + password + '\'' + 69 | '}'; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # \u626B\u63CF\u7684\u5305\u8DEF\u5F84,\u9ED8\u8BA4\u626B\u63CF\u6240\u6709 2 | spring.swagger.base-package=com.battcn 3 | spring.swagger.enabled=true 4 | # \u4E2D\u6587\u5206\u7EC4\u9700\u8981\u8F6C\u6362\u6210 ASCII 5 | spring.swagger.groups[\u7528\u6237].basePackage=com.battcn.controller.user 6 | spring.swagger.groups[\u4E66\u7C4D].basePackage=com.battcn.controller.book -------------------------------------------------------------------------------- /swagger-spring-boot-samples/swagger-spring-boot-sample-group/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | swagger: 3 | enabled: true 4 | base-package: com.battcn 5 | groups: 6 | [用户]: 7 | base-package: com.battcn.controller.user 8 | [书籍]: 9 | base-package: com.battcn.controller.order -------------------------------------------------------------------------------- /swagger-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.battcn 8 | swagger-spring-boot 9 | 2.1.5-RELEASE 10 | 11 | swagger-spring-boot-starter 12 | swagger-spring-boot-starter 13 | jar 14 | ${parent.version} 15 | 16 | 17 | 18 | com.battcn 19 | swagger-spring-boot-autoconfigure 20 | ${project.parent.version} 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | ${project.basedir}/src/main/resources 29 | META-INF/resources/ 30 | 31 | 32 | 33 | 34 | 35 | org.apache.maven.plugins 36 | maven-compiler-plugin 37 | 38 | ${java.version} 39 | ${java.version} 40 | ${project.build.sourceEncoding} 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /swagger-spring-boot-starter/src/main/resources/META-INF/spring.provides: -------------------------------------------------------------------------------- 1 | provides: swagger-spring-boot-autoconfigure,swagger,springfox-swagger2,swagger-vue-ui -------------------------------------------------------------------------------- /swagger-vue-ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.battcn 8 | swagger-spring-boot 9 | 2.1.5-RELEASE 10 | 11 | swagger-vue-ui 12 | jar 13 | swagger-vue-ui 14 | ${parent.version} 15 | 16 | 17 | UTF-8 18 | 1.8 19 | 20 | 21 | 22 | 23 | 24 | ${project.basedir}/src/main/resources 25 | META-INF/resources/ 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | 34 | ${java.version} 35 | ${java.version} 36 | ${project.build.sourceEncoding} 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /swagger-vue-ui/src/main/resources/static/js/manifest.37a2ecbb1d1b7e6c9ada.js: -------------------------------------------------------------------------------- 1 | !function(r){function n(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,n),t.l=!0,t.exports}var e=window.webpackJsonp;window.webpackJsonp=function(o,u,c){for(var f,i,p,a=0,l=[];avue-swagger-ui
-------------------------------------------------------------------------------- /swagger-vue/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "modules": false, 5 | "targets": { 6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-vue-jsx", "transform-runtime"] 12 | } 13 | -------------------------------------------------------------------------------- /swagger-vue/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /swagger-vue/.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | "postcss-import": {}, 6 | "postcss-url": {}, 7 | // to edit target browsers: use "browserslist" field in package.json 8 | "autoprefixer": {} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /swagger-vue/build/build.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | require('./check-versions')() 3 | 4 | process.env.NODE_ENV = 'production' 5 | 6 | const ora = require('ora') 7 | const rm = require('rimraf') 8 | const path = require('path') 9 | const chalk = require('chalk') 10 | const webpack = require('webpack') 11 | const config = require('../config') 12 | const webpackConfig = require('./webpack.prod.conf') 13 | 14 | const spinner = ora('building for production...') 15 | spinner.start() 16 | 17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 18 | if (err) throw err 19 | webpack(webpackConfig, (err, stats) => { 20 | spinner.stop() 21 | if (err) throw err 22 | process.stdout.write(stats.toString({ 23 | colors: true, 24 | modules: false, 25 | children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build. 26 | chunks: false, 27 | chunkModules: false 28 | }) + '\n\n') 29 | 30 | if (stats.hasErrors()) { 31 | console.log(chalk.red(' Build failed with errors.\n')) 32 | process.exit(1) 33 | } 34 | 35 | console.log(chalk.cyan(' Build complete.\n')) 36 | console.log(chalk.yellow( 37 | ' Tip: built files are meant to be served over an HTTP server.\n' + 38 | ' Opening index.html over file:// won\'t work.\n' 39 | )) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /swagger-vue/build/check-versions.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const chalk = require('chalk') 3 | const semver = require('semver') 4 | const packageConfig = require('../package.json') 5 | const shell = require('shelljs') 6 | 7 | function exec (cmd) { 8 | return require('child_process').execSync(cmd).toString().trim() 9 | } 10 | 11 | const versionRequirements = [ 12 | { 13 | name: 'node', 14 | currentVersion: semver.clean(process.version), 15 | versionRequirement: packageConfig.engines.node 16 | } 17 | ] 18 | 19 | if (shell.which('npm')) { 20 | versionRequirements.push({ 21 | name: 'npm', 22 | currentVersion: exec('npm --version'), 23 | versionRequirement: packageConfig.engines.npm 24 | }) 25 | } 26 | 27 | module.exports = function () { 28 | const warnings = [] 29 | 30 | for (let i = 0; i < versionRequirements.length; i++) { 31 | const mod = versionRequirements[i] 32 | 33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 34 | warnings.push(mod.name + ': ' + 35 | chalk.red(mod.currentVersion) + ' should be ' + 36 | chalk.green(mod.versionRequirement) 37 | ) 38 | } 39 | } 40 | 41 | if (warnings.length) { 42 | console.log('') 43 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 44 | console.log() 45 | 46 | for (let i = 0; i < warnings.length; i++) { 47 | const warning = warnings[i] 48 | console.log(' ' + warning) 49 | } 50 | 51 | console.log() 52 | process.exit(1) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /swagger-vue/build/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/swagger-vue/build/logo.png -------------------------------------------------------------------------------- /swagger-vue/build/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const config = require('../config') 4 | const ExtractTextPlugin = require('extract-text-webpack-plugin') 5 | const packageConfig = require('../package.json') 6 | 7 | exports.assetsPath = function (_path) { 8 | const assetsSubDirectory = process.env.NODE_ENV === 'production' 9 | ? config.build.assetsSubDirectory 10 | : config.dev.assetsSubDirectory 11 | 12 | return path.posix.join(assetsSubDirectory, _path) 13 | } 14 | 15 | exports.cssLoaders = function (options) { 16 | options = options || {} 17 | 18 | const cssLoader = { 19 | loader: 'css-loader', 20 | options: { 21 | sourceMap: options.sourceMap 22 | } 23 | } 24 | 25 | const postcssLoader = { 26 | loader: 'postcss-loader', 27 | options: { 28 | sourceMap: options.sourceMap 29 | } 30 | } 31 | 32 | // generate loader string to be used with extract text plugin 33 | function generateLoaders (loader, loaderOptions) { 34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] 35 | 36 | if (loader) { 37 | loaders.push({ 38 | loader: loader + '-loader', 39 | options: Object.assign({}, loaderOptions, { 40 | sourceMap: options.sourceMap 41 | }) 42 | }) 43 | } 44 | 45 | // Extract CSS when that option is specified 46 | // (which is the case during production build) 47 | if (options.extract) { 48 | return ExtractTextPlugin.extract({ 49 | use: loaders, 50 | fallback: 'vue-style-loader' 51 | }) 52 | } else { 53 | return ['vue-style-loader'].concat(loaders) 54 | } 55 | } 56 | 57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 58 | return { 59 | css: generateLoaders(), 60 | postcss: generateLoaders(), 61 | less: generateLoaders('less'), 62 | sass: generateLoaders('sass', { indentedSyntax: true }), 63 | scss: generateLoaders('sass'), 64 | stylus: generateLoaders('stylus'), 65 | styl: generateLoaders('stylus') 66 | } 67 | } 68 | 69 | // Generate loaders for standalone style files (outside of .vue) 70 | exports.styleLoaders = function (options) { 71 | const output = [] 72 | const loaders = exports.cssLoaders(options) 73 | 74 | for (const extension in loaders) { 75 | const loader = loaders[extension] 76 | output.push({ 77 | test: new RegExp('\\.' + extension + '$'), 78 | use: loader 79 | }) 80 | } 81 | 82 | return output 83 | } 84 | 85 | exports.createNotifierCallback = () => { 86 | const notifier = require('node-notifier') 87 | 88 | return (severity, errors) => { 89 | if (severity !== 'error') return 90 | 91 | const error = errors[0] 92 | const filename = error.file && error.file.split('!').pop() 93 | 94 | notifier.notify({ 95 | title: packageConfig.name, 96 | message: severity + ': ' + error.name, 97 | subtitle: filename || '', 98 | icon: path.join(__dirname, 'logo.png') 99 | }) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /swagger-vue/build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const utils = require('./utils') 3 | const config = require('../config') 4 | const isProduction = process.env.NODE_ENV === 'production' 5 | const sourceMapEnabled = isProduction 6 | ? config.build.productionSourceMap 7 | : config.dev.cssSourceMap 8 | 9 | module.exports = { 10 | loaders: utils.cssLoaders({ 11 | sourceMap: sourceMapEnabled, 12 | extract: isProduction 13 | }), 14 | cssSourceMap: sourceMapEnabled, 15 | cacheBusting: config.dev.cacheBusting, 16 | transformToRequire: { 17 | video: ['src', 'poster'], 18 | source: 'src', 19 | img: 'src', 20 | image: 'xlink:href' 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /swagger-vue/build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path') 3 | const utils = require('./utils') 4 | const config = require('../config') 5 | const vueLoaderConfig = require('./vue-loader.conf') 6 | 7 | function resolve (dir) { 8 | return path.join(__dirname, '..', dir) 9 | } 10 | 11 | 12 | 13 | module.exports = { 14 | context: path.resolve(__dirname, '../'), 15 | entry: { 16 | app: ["babel-polyfill","./src/main.js"] 17 | }, 18 | output: { 19 | path: config.build.assetsRoot, 20 | filename: '[name].js', 21 | publicPath: process.env.NODE_ENV === 'production' 22 | ? config.build.assetsPublicPath 23 | : config.dev.assetsPublicPath 24 | }, 25 | resolve: { 26 | extensions: ['.js', '.vue', '.json'], 27 | alias: {/* 别名配置 */ 28 | 'vue$': 'vue/dist/vue.esm.js', 29 | '@': resolve('src'), 30 | } 31 | }, 32 | module: { 33 | rules: [ 34 | { 35 | test: /\.vue$/, 36 | loader: 'vue-loader', 37 | options: vueLoaderConfig 38 | }, 39 | { 40 | test: /\.js$/, 41 | loader: 'babel-loader', 42 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] 43 | }, 44 | { 45 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 46 | loader: 'url-loader', 47 | options: { 48 | limit: 10000, 49 | name: utils.assetsPath('img/[name].[ext]') 50 | } 51 | }, 52 | { 53 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, 54 | loader: 'url-loader', 55 | options: { 56 | limit: 10000, 57 | name: utils.assetsPath('media/[name].[hash:7].[ext]') 58 | } 59 | }, 60 | { 61 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 62 | loader: 'url-loader', 63 | options: { 64 | limit: 10000, 65 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 66 | } 67 | } 68 | ] 69 | }, 70 | node: { 71 | // prevent webpack from injecting useless setImmediate polyfill because Vue 72 | // source contains it (although only uses it if it's native). 73 | setImmediate: false, 74 | // prevent webpack from injecting mocks to Node native modules 75 | // that does not make sense for the client 76 | dgram: 'empty', 77 | fs: 'empty', 78 | net: 'empty', 79 | tls: 'empty', 80 | child_process: 'empty' 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /swagger-vue/build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const utils = require('./utils'); 3 | const webpack = require('webpack'); 4 | const config = require('../config'); 5 | const merge = require('webpack-merge'); 6 | const path = require('path'); 7 | const baseWebpackConfig = require('./webpack.base.conf'); 8 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 9 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin'); 11 | const portfinder = require('portfinder'); 12 | 13 | const HOST = process.env.HOST 14 | const PORT = process.env.PORT && Number(process.env.PORT) 15 | 16 | const devWebpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true }) 19 | }, 20 | // cheap-module-eval-source-map is faster for development 21 | devtool: config.dev.devtool, 22 | 23 | // these devServer options should be customized in /config/index.js 24 | devServer: { 25 | clientLogLevel: 'warning', 26 | historyApiFallback: { 27 | rewrites: [ 28 | { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, 29 | /* 此处导致路由重定向正常运行,但是普通刷新,路由路径输入会找不到页面, 30 | 正常代码: 31 | { from: /.*!/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }, 32 | 原先代码: (少了.posix) 33 | { from: /.*!/, to: path.join(config.dev.assetsPublicPath, 'index.html') },*/ 34 | 35 | ], 36 | }, 37 | hot: true, 38 | contentBase: false, // since we use CopyWebpackPlugin. 39 | compress: true, 40 | host: HOST || config.dev.host, 41 | port: PORT || config.dev.port, 42 | open: config.dev.autoOpenBrowser, 43 | overlay: config.dev.errorOverlay 44 | ? { warnings: false, errors: true } 45 | : false, 46 | publicPath: config.dev.assetsPublicPath, 47 | proxy: config.dev.proxyTable, 48 | quiet: true, // necessary for FriendlyErrorsPlugin 49 | watchOptions: { 50 | poll: config.dev.poll, 51 | } 52 | }, 53 | plugins: [ 54 | new webpack.DefinePlugin({ 55 | 'process.env': require('../config/dev.env') 56 | }), 57 | new webpack.HotModuleReplacementPlugin(), 58 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update. 59 | new webpack.NoEmitOnErrorsPlugin(), 60 | // https://github.com/ampedandwired/html-webpack-plugin 61 | new HtmlWebpackPlugin({ 62 | filename: 'index.html', 63 | template: 'index.html', 64 | inject: true 65 | }), 66 | // copy custom static assets 67 | new CopyWebpackPlugin([ 68 | { 69 | from: path.resolve(__dirname, '../static'), 70 | to: config.dev.assetsSubDirectory, 71 | ignore: ['.*'] 72 | } 73 | ]) 74 | ] 75 | }) 76 | 77 | module.exports = new Promise((resolve, reject) => { 78 | portfinder.basePort = process.env.PORT || config.dev.port 79 | portfinder.getPort((err, port) => { 80 | if (err) { 81 | reject(err) 82 | } else { 83 | // publish the new Port, necessary for e2e tests 84 | process.env.PORT = port 85 | // add port to devServer config 86 | devWebpackConfig.devServer.port = port 87 | 88 | // Add FriendlyErrorsPlugin 89 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({ 90 | compilationSuccessInfo: { 91 | messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`], 92 | }, 93 | onErrors: config.dev.notifyOnErrors 94 | ? utils.createNotifierCallback() 95 | : undefined 96 | })) 97 | 98 | resolve(devWebpackConfig) 99 | } 100 | }) 101 | }) 102 | -------------------------------------------------------------------------------- /swagger-vue/build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | const path = require('path'); 3 | const utils = require('./utils'); 4 | const webpack = require('webpack'); 5 | const config = require('../config'); 6 | const merge = require('webpack-merge'); 7 | const baseWebpackConfig = require('./webpack.base.conf'); 8 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 9 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin'); 11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin'); 12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 13 | 14 | const env = require('../config/prod.env'); 15 | 16 | const webpackConfig = merge(baseWebpackConfig, { 17 | module: { 18 | rules: utils.styleLoaders({ 19 | sourceMap: config.build.productionSourceMap, 20 | extract: true, 21 | usePostCSS: true 22 | }) 23 | }, 24 | devtool: config.build.productionSourceMap ? config.build.devtool : false, 25 | output: { 26 | path: config.build.assetsRoot, 27 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 28 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 29 | }, 30 | plugins: [ 31 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 32 | new webpack.DefinePlugin({ 33 | 'process.env': env 34 | }), 35 | new UglifyJsPlugin({ 36 | uglifyOptions: { 37 | compress: { 38 | warnings: false 39 | } 40 | }, 41 | sourceMap: config.build.productionSourceMap, 42 | parallel: true 43 | }), 44 | // extract css into its own file 45 | new ExtractTextPlugin({ 46 | filename: utils.assetsPath('css/[name].[contenthash].css'), 47 | // Setting the following option to `false` will not extract CSS from codesplit chunks. 48 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack. 49 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, 50 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110 51 | allChunks: true, 52 | }), 53 | // Compress extracted CSS. We are using this plugin so that possible 54 | // duplicated CSS from different components can be deduped. 55 | new OptimizeCSSPlugin({ 56 | cssProcessorOptions: config.build.productionSourceMap 57 | ? {safe: true, map: {inline: false}} 58 | : {safe: true} 59 | }), 60 | // generate dist index.html with correct asset hash for caching. 61 | // you can customize output by editing /index.html 62 | // see https://github.com/ampedandwired/html-webpack-plugin 63 | new HtmlWebpackPlugin({ 64 | filename: config.build.index, 65 | template: 'index.html', 66 | inject: true, 67 | minify: { 68 | removeComments: true, 69 | collapseWhitespace: true, 70 | removeAttributeQuotes: true 71 | // more options: 72 | // https://github.com/kangax/html-minifier#options-quick-reference 73 | }, 74 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 75 | chunksSortMode: 'dependency' 76 | }), 77 | // keep module.id stable when vendor modules does not change 78 | new webpack.HashedModuleIdsPlugin(), 79 | // enable scope hoisting 80 | new webpack.optimize.ModuleConcatenationPlugin(), 81 | // split vendor js into its own file 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'vendor', 84 | minChunks (module) { 85 | // any required modules inside node_modules are extracted to vendor 86 | return ( 87 | module.resource && 88 | /\.js$/.test(module.resource) && 89 | module.resource.indexOf( 90 | path.join(__dirname, '../node_modules') 91 | ) === 0 92 | ) 93 | } 94 | }), 95 | // extract webpack runtime and module manifest to its own file in order to 96 | // prevent vendor hash from being updated whenever app bundle is updated 97 | new webpack.optimize.CommonsChunkPlugin({ 98 | name: 'manifest', 99 | minChunks: Infinity 100 | }), 101 | // This instance extracts shared chunks from code splitted chunks and bundles them 102 | // in a separate chunk, similar to the vendor chunk 103 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk 104 | new webpack.optimize.CommonsChunkPlugin({ 105 | name: 'app', 106 | async: 'vendor-async', 107 | children: true, 108 | minChunks: 3 109 | }), 110 | 111 | // copy custom static assets 112 | new CopyWebpackPlugin([ 113 | { 114 | from: path.resolve(__dirname, '../static'), 115 | to: config.build.assetsSubDirectory, 116 | ignore: ['.*'] 117 | } 118 | ]) 119 | ] 120 | }) 121 | 122 | if (config.build.productionGzip) { 123 | const CompressionWebpackPlugin = require('compression-webpack-plugin') 124 | 125 | webpackConfig.plugins.push( 126 | new CompressionWebpackPlugin({ 127 | asset: '[path].gz[query]', 128 | algorithm: 'gzip', 129 | test: new RegExp( 130 | '\\.(' + 131 | config.build.productionGzipExtensions.join('|') + 132 | ')$' 133 | ), 134 | threshold: 10240, 135 | minRatio: 0.8 136 | }) 137 | ) 138 | } 139 | 140 | if (config.build.bundleAnalyzerReport) { 141 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 142 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 143 | } 144 | 145 | module.exports = webpackConfig; 146 | -------------------------------------------------------------------------------- /swagger-vue/config/dev.env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const merge = require('webpack-merge'); 3 | const prodEnv = require('./prod.env'); 4 | 5 | module.exports = merge(prodEnv, { 6 | NODE_ENV: '"development"', 7 | SWAGGER_URL: '"http://localhost:8080"' 8 | }); 9 | -------------------------------------------------------------------------------- /swagger-vue/config/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | // Template version: 1.2.8 3 | // see http://vuejs-templates.github.io/webpack for documentation. 4 | 5 | const path = require('path'); 6 | 7 | module.exports = { 8 | dev: { 9 | 10 | // Paths 11 | assetsSubDirectory: 'static', 12 | assetsPublicPath: '/', 13 | proxyTable: {}, 14 | 15 | // Various Dev Server settings 16 | host: 'localhost', // can be overwritten by process.env.HOST 17 | port: 8081, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined 18 | autoOpenBrowser: false, 19 | errorOverlay: true, 20 | notifyOnErrors: true, 21 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- 22 | 23 | 24 | /** 25 | * Source Maps 26 | */ 27 | 28 | // https://webpack.js.org/configuration/devtool/#development 29 | devtool: 'cheap-module-eval-source-map', 30 | 31 | // If you have problems debugging vue-files in devtools, 32 | // set this to false - it *may* help 33 | // https://vue-loader.vuejs.org/en/options.html#cachebusting 34 | cacheBusting: true, 35 | 36 | cssSourceMap: true, 37 | }, 38 | 39 | build: { 40 | // Template for index.html 41 | index: path.resolve(__dirname, '../dist/swagger-ui.html'), 42 | 43 | // Paths 44 | assetsRoot: path.resolve(__dirname, '../dist'), 45 | assetsSubDirectory: 'static', 46 | assetsPublicPath: '', 47 | 48 | /** 49 | * Source Maps 50 | */ 51 | 52 | productionSourceMap: true, 53 | // https://webpack.js.org/configuration/devtool/#production 54 | devtool: '#source-map', 55 | 56 | // Gzip off by default as many popular static hosts such as 57 | // Surge or Netlify already gzip all static assets for you. 58 | // Before setting to `true`, make sure to: 59 | // npm install --save-dev compression-webpack-plugin 60 | productionGzip: false, 61 | productionGzipExtensions: ['js', 'css'], 62 | 63 | // Run the build command with an extra argument to 64 | // View the bundle analyzer report after build finishes: 65 | // `npm run build --report` 66 | // Set to `true` or `false` to always turn it on or off 67 | bundleAnalyzerReport: process.env.npm_config_report 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /swagger-vue/config/prod.env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = { 3 | NODE_ENV: '"production"', 4 | SWAGGER_URL: '""' 5 | } 6 | -------------------------------------------------------------------------------- /swagger-vue/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | vue-swagger-ui 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /swagger-vue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-swagger", 3 | "version": "1.0.0", 4 | "description": "A Vue.js project", 5 | "author": "_Rock <995269937@qq.com>", 6 | "private": true, 7 | "scripts": { 8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js", 9 | "start": "npm run dev", 10 | "build": "node build/build.js" 11 | }, 12 | "dependencies": { 13 | "axios": "^0.18.0", 14 | "babel-polyfill": "^6.26.0", 15 | "build": "^0.1.4", 16 | "clipboard": "^2.0.1", 17 | "lodash": "^4.17.10", 18 | "prod": "^1.0.1", 19 | "ssri": "^5.2.2", 20 | "vue": "^2.5.2", 21 | "vue-layer": "^0.8.5", 22 | "vue-router": "^3.0.1", 23 | "vuex": "^3.0.1" 24 | }, 25 | "devDependencies": { 26 | "autoprefixer": "^7.1.2", 27 | "babel-core": "^6.22.1", 28 | "babel-helper-vue-jsx-merge-props": "^2.0.3", 29 | "babel-loader": "^7.1.1", 30 | "babel-plugin-syntax-jsx": "^6.18.0", 31 | "babel-plugin-transform-runtime": "^6.22.0", 32 | "babel-plugin-transform-vue-jsx": "^3.5.0", 33 | "babel-preset-env": "^1.3.2", 34 | "babel-preset-stage-2": "^6.22.0", 35 | "chalk": "^2.0.1", 36 | "copy-webpack-plugin": "^4.0.1", 37 | "css-loader": "^0.28.0", 38 | "extract-text-webpack-plugin": "^3.0.0", 39 | "file-loader": "^1.1.4", 40 | "friendly-errors-webpack-plugin": "^1.6.1", 41 | "html-webpack-plugin": "^2.30.1", 42 | "node-notifier": "^5.1.2", 43 | "normalize.css": "^7.0.0", 44 | "optimize-css-assets-webpack-plugin": "^3.2.0", 45 | "ora": "^1.2.0", 46 | "portfinder": "^1.0.13", 47 | "postcss-import": "^11.0.0", 48 | "postcss-loader": "^2.0.8", 49 | "postcss-url": "^7.2.1", 50 | "rimraf": "^2.6.0", 51 | "semver": "^5.3.0", 52 | "shelljs": "^0.7.6", 53 | "uglifyjs-webpack-plugin": "^1.1.1", 54 | "url-loader": "^0.5.8", 55 | "vue-loader": "^13.3.0", 56 | "vue-style-loader": "^3.0.1", 57 | "vue-template-compiler": "^2.5.2", 58 | "webpack": "^3.12.0", 59 | "webpack-bundle-analyzer": "^2.9.0", 60 | "webpack-dev-server": "^2.9.1", 61 | "webpack-merge": "^4.1.0" 62 | }, 63 | "engines": { 64 | "node": ">= 6.0.0", 65 | "npm": ">= 3.0.0" 66 | }, 67 | "browserslist": [ 68 | "> 1%", 69 | "last 2 versions", 70 | "not ie <= 8" 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /swagger-vue/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 18 | 19 | 56 | -------------------------------------------------------------------------------- /swagger-vue/src/api/accounts.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import {SWAGGER_LOGIN, SWAGGER_SECURITY, SWAGGER_URL} from './config' 3 | 4 | export function isVerify() { 5 | return axios.get(SWAGGER_URL + SWAGGER_SECURITY).then((res) => { 6 | return Promise.resolve(res) 7 | }) 8 | } 9 | 10 | export function login(params) { 11 | let url = SWAGGER_LOGIN; 12 | if (params !== undefined && params !== null && JSON.stringify(params) !== "{}") { 13 | url += '?'; 14 | for (let key in params) { 15 | url += `${key}=${params[key]}&`; 16 | } 17 | url = url.slice(0, url.length - 1); 18 | } 19 | return axios.post(url).then((res) => { 20 | return Promise.resolve(res) 21 | }) 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /swagger-vue/src/api/config.js: -------------------------------------------------------------------------------- 1 | //js获取项目根路径,如: http://localhost:8080/battcn 2 | const getBaseURL = () => { 3 | const urlMatches = /(.*)\/swagger-ui.html.*/.exec(window.location.href); 4 | return urlMatches&&urlMatches[1]; 5 | }; 6 | 7 | const SWAGGER_URL = process.env.SWAGGER_URL === "" ? getBaseURL() : process.env.SWAGGER_URL; 8 | 9 | 10 | //const SWAGGER_URL = getBaseURL(); 11 | /* 获取单选框数据链接 */ 12 | const SWAGGER_RESOURCES = SWAGGER_URL + '/swagger-resources'; 13 | 14 | /* 判断是否需要账号验证接口链接 */ 15 | const SWAGGER_SECURITY = SWAGGER_URL + '/v3/swagger-security'; 16 | /* 账号登录验证 */ 17 | const SWAGGER_LOGIN = SWAGGER_URL + '/v3/swagger-login'; 18 | 19 | /* 响应码 */ 20 | const HTTP_STATUS = {min: 200, max: 299, logCode: 401}; 21 | /* 颜色 */ 22 | const BG = {GET: '#D1EAFF', POST: '#D1FED3', PATCH: '#FFE2D2', DELETE: '#FFD1D1', PUT: "#F0E0CA"} 23 | /* 消息提示语 */ 24 | const MESSAGES = { 25 | ERROR: "请求发送失败", 26 | SUCCESS: "请求发送成功 ", 27 | PERMISSION_ERROR: '身份验证失败啦,请进行身份验证后使用!', 28 | LOAD_STATUS: '加载失败' 29 | }; 30 | /* 弹窗提示语 */ 31 | const POPUPS_MESSAGES = { 32 | SUCCESS: "修改 X-Authorization 成功", 33 | REQUIRED: "为必选字段", 34 | FORMAT_JSON: " 不为JSON格式,请重新输入!" 35 | } 36 | /* 对象色阶 */ 37 | const BGFORM = ["#FFFFFF", "#F5F5F5", "#E6E6E6", "#CCCCCC", "#C9C9C9", "#C2C2C2"]; 38 | 39 | export { 40 | SWAGGER_URL, 41 | SWAGGER_SECURITY, 42 | SWAGGER_LOGIN, 43 | SWAGGER_RESOURCES, 44 | HTTP_STATUS, 45 | BG, 46 | MESSAGES, 47 | POPUPS_MESSAGES, 48 | BGFORM 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /swagger-vue/src/api/data.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import {SWAGGER_RESOURCES, SWAGGER_URL} from './config' 3 | 4 | export function getDropDown() { 5 | return axios.get(SWAGGER_RESOURCES).then((res) => { 6 | return Promise.resolve(res) 7 | }) 8 | } 9 | export function getBoxContent(urlSuffix) { 10 | return axios.get(SWAGGER_URL + urlSuffix).then((res) => { 11 | return Promise.resolve(res) 12 | }) 13 | } 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /swagger-vue/src/api/debug_request.js: -------------------------------------------------------------------------------- 1 | import axios from "axios" 2 | import {SWAGGER_URL} from './config' 3 | 4 | export function getDebugRequest(requestData) { 5 | let data = Object.assign({}, requestData, {}); 6 | // responseType:data.responseType||'json' 7 | return axios.request({ 8 | url: SWAGGER_URL + data.url, 9 | data: data.data, 10 | method: data.type.toUpperCase(), 11 | headers: data.headerParams, 12 | responseType: data.responseType || 'text' 13 | }).then((res) => { 14 | return Promise.resolve(res) 15 | }) 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /swagger-vue/src/common/util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * json数据格式化缩进(带dom标签,字体颜色) 3 | * @param json数据 4 | * @returns {} 缩进后的json数据 5 | */ 6 | const syntaxHighlight = function (json) { 7 | if (json === undefined) { 8 | return undefined; 9 | } 10 | json = json.replace(/&/g, '&').replace(//g, '>'); 11 | return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { 12 | var cls = 'number'; 13 | if (/^"/.test(match)) { 14 | if (/:$/.test(match)) { 15 | cls = 'key'; 16 | } else { 17 | cls = 'string'; 18 | } 19 | } else if (/true|false/.test(match)) { 20 | cls = 'boolean'; 21 | } else if (/null/.test(match)) { 22 | cls = 'null'; 23 | } 24 | return '' + match + ''; 25 | }); 26 | } 27 | /** 28 | * 显示提示 29 | * @param hint 显示的提示语内容 30 | */ 31 | const promptPopUpShow = function (hint) {/* */ 32 | this.$layer.msg(hint, {time: 2}); 33 | } 34 | /** 35 | * 对象拷贝 36 | * @param source 对象类型数据 37 | * @returns {*} 深层拷贝生成的对象类型数据 38 | */ 39 | const deepCopy = function (source) { 40 | let result = ""; 41 | if (source === undefined || source === null) { 42 | return undefined; 43 | } 44 | if (typeof source === 'object') { 45 | if (source.constructor === Array) { 46 | return treatArray(source); 47 | } 48 | return treatObj(source); 49 | // return JSON.parse(JSON.stringify(source)); 50 | } else { 51 | return source; 52 | } 53 | 54 | /** 55 | * 对象类型数据的复制 56 | * @param source 对象类型数据 57 | * @returns {*} 深层拷贝生成的单个对象类型数据 58 | */ 59 | function treatObj(source) { // 60 | result = {}; 61 | for (let key in source) { 62 | result[key] = deepCopy(source[key]); 63 | // result[key] = val?val:{}; 64 | } 65 | return result; 66 | } 67 | 68 | /** 69 | * list数组类型数据的拷贝 70 | * @param source list数组类型数据 71 | * @returns [] 深层拷贝生成的单个list数组类型数据 72 | */ 73 | function treatArray(source) { //处理 74 | result = []; 75 | for (let key in source) { 76 | result.push(deepCopy(source[key])); 77 | } 78 | return result; 79 | } 80 | 81 | /** 82 | * 处理基本类型拷贝 83 | * @param source 基本类型数据 84 | * @returns string || Boolean || Number 拷贝生成的单个基本类型数据 85 | */ 86 | function treatBasic(source) { // 87 | result = source; 88 | return result; 89 | } 90 | }; 91 | /** 92 | * 传入参数类型名字,返回该类型初始化的值 93 | * @param type 参数类型名字 94 | * @returns {*} 该类型初始化的值 95 | */ 96 | const basicTypeInit = function (type) { 97 | if (type === 'integer' || type === 'number') { 98 | return 0; 99 | } 100 | if (type === 'boolean') { 101 | return 'false' 102 | } 103 | if (type === 'string') { 104 | return "" 105 | } 106 | if (type === 'array') { 107 | return [] 108 | } 109 | if (type === 'file') { 110 | return {type: "file", in: "formData"} 111 | } 112 | }; 113 | /** 114 | * JSON数据格式化(将其以 上下展开形式 返回,不带dom标签及颜色) 115 | * @param text_value JSON数据 116 | * @returns string 格式化缩进后的json字符串 117 | */ 118 | const formatterJson = function (text_value) {/* */ 119 | if (text_value === undefined) { 120 | return undefined; 121 | } 122 | let res = ""; 123 | for (let i = 0, j = 0, k = 0, ii, ele; i < text_value.length; i++) {//k:缩进,j:""个数 124 | ele = text_value.charAt(i); 125 | if (j % 2 === 0 && (ele === "}" || ele === "]")) { 126 | k--; 127 | for (ii = 0; ii < k; ii++) ele = " " + ele; 128 | ele = "\n" + ele; 129 | } 130 | else if (j % 2 === 0 && (ele === "{" || ele === "[")) { 131 | ele += "\n"; 132 | k++; 133 | //debugger; 134 | for (ii = 0; ii < k; ii++) ele += " "; 135 | } 136 | else if (j % 2 === 0 && ele === ",") { 137 | ele += "\n"; 138 | for (ii = 0; ii < k; ii++) ele += " "; 139 | } 140 | else if (ele === "\"") j++; 141 | res += ele; 142 | } 143 | return res; 144 | }; 145 | export { 146 | deepCopy, basicTypeInit, formatterJson, promptPopUpShow, syntaxHighlight 147 | } 148 | -------------------------------------------------------------------------------- /swagger-vue/src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import App from './App' 5 | import "babel-polyfill" 6 | import router from './router' 7 | import store from './store/index' 8 | import layer from 'vue-layer' 9 | 10 | 11 | 12 | 13 | 14 | Vue.config.productionTip = false 15 | Vue.prototype.$layer = layer(Vue); 16 | /* eslint-disable no-new */ 17 | new Vue({ 18 | el: '#app', 19 | store, 20 | template: '', 21 | components: {App}, 22 | router 23 | }); 24 | 25 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/about/index.vue: -------------------------------------------------------------------------------- 1 | 35 | 79 | 137 | 138 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/about/status.vue: -------------------------------------------------------------------------------- 1 | 13 | 20 | 63 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/util/operate/authorizations.vue: -------------------------------------------------------------------------------- 1 | 25 | 90 | 210 | 211 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/util/operate/pop_ups.vue: -------------------------------------------------------------------------------- 1 | 14 | 20 | 48 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/util/view/form_fold.vue: -------------------------------------------------------------------------------- 1 | 28 | 81 | 169 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/util/view/json_view.vue: -------------------------------------------------------------------------------- 1 | 40 | 62 | 113 | 114 | -------------------------------------------------------------------------------- /swagger-vue/src/pages/view/login.vue: -------------------------------------------------------------------------------- 1 | 16 | 70 | 151 | -------------------------------------------------------------------------------- /swagger-vue/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import list from './../pages/view/list.vue'; 4 | 5 | Vue.use(Router); 6 | 7 | export default new Router({ 8 | mode: 'history', 9 | routes: [ 10 | { 11 | path: '/', 12 | name: 'swagger', 13 | redirect: '/swagger-ui.html' 14 | }, 15 | { 16 | path: '(\.*)/swagger-ui.html', 17 | name: 'swagger-ui', 18 | component: list 19 | } 20 | ] 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /swagger-vue/src/store/actions.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/battcn/swagger-spring-boot/a7c30c830518cdec96757808cfb844015455149b/swagger-vue/src/store/actions.js -------------------------------------------------------------------------------- /swagger-vue/src/store/getters.js: -------------------------------------------------------------------------------- 1 | export const debugRequestCount = state => state.debugRequestCount 2 | export const debugResponse = state => state.debugResponse 3 | export const debugRequestTime = state => state.debugRequestTime 4 | export const debugAuthorizeObj = state => state.debugAuthorizeObj 5 | export const debugAuthorization = state => state.debugAuthorization 6 | 7 | export const tabDataInfo = state => state.tabDataInfo 8 | 9 | 10 | export const tabDataShow = state => state.tabDataShow 11 | 12 | export const accountIsSecurity = state => state.accountIsSecurity 13 | 14 | export const dropDownData = state => state.dropDownData 15 | 16 | export const dropDownCount = state => state.dropDownCount 17 | 18 | export const dropDownBoxContent = state => state.dropDownBoxContent 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /swagger-vue/src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import "babel-polyfill" 3 | import Vuex from "vuex"; 4 | import * as actions from './actions' 5 | import * as getters from './getters' 6 | import state from './state' 7 | import mutations from './mutations' 8 | // import createLogger from 'vuex/dist/logger' 9 | 10 | 11 | Vue.use(Vuex); 12 | 13 | const debug = process.env.NODE_ENV !== 'production' 14 | export default new Vuex.Store({ 15 | actions, 16 | getters, 17 | mutations, 18 | state, 19 | /*strict:debug, 20 | plugins:debug?[createLogger()]:[]*/ 21 | }) 22 | 23 | -------------------------------------------------------------------------------- /swagger-vue/src/store/mutations.js: -------------------------------------------------------------------------------- 1 | import * as types from './mutations_types' 2 | import Vue from 'vue' 3 | const mutations = { 4 | [types.SET_DEBUGREQUEST_COUNT](state, count) { 5 | state.debugRequestCount = count 6 | }, 7 | [types.SET_DEBUGREQUEST_RESPONSE](state, response) { 8 | state.debugResponse = response 9 | }, 10 | [types.SET_DEBUGREQUEST_REQUESTTIME](state, time) { 11 | state.debugRequestTime = time 12 | }, 13 | [types.SET_DEBUGREQUEST_SECRETKEYS](state, secretkeys) { 14 | state.debugAuthorizeObj = secretkeys 15 | }, 16 | [types.SET_DEBUGREQUEST_SECRETKEY](state, secretkey) { 17 | state.debugAuthorization = secretkey 18 | }, 19 | /* tab页数据*/ 20 | [types.INSERT_TABDATA_ADDTAB](state, infoDataItem) { 21 | Vue.set(state.tabDataInfo, infoDataItem.key, infoDataItem.value) 22 | }, 23 | [types.SELETE_TABDATA_INFODATAITEM](state, key) { 24 | return state.tabDataInfo[key] || undefined; 25 | }, 26 | [types.UPDATE_TABDATA_INFODATA](state, data) { 27 | data.length > 1 ? Vue.set(state.tabDataInfo, data[0], data[1]) : ""; 28 | }, 29 | [types.DELETE_TABDATA_DELETETAB](state, key) { 30 | if (key && state.tabDataInfo[key] !== undefined) { 31 | Vue.delete(state.tabDataInfo, key) 32 | } 33 | }, 34 | [types.CLEAR_TABDATA_CLEARTAB](state) { 35 | state.tabDataInfo = {} 36 | }, 37 | [types.UPDATE_TABDATA_UPDATETABSHOW](state, val) { 38 | state.tabDataShow = val 39 | }, 40 | /* 账号验证 */ 41 | /* 判断是否设置账户验证 */ 42 | [types.DECIDE_ACCOUNT_ISVERIFY](state, security) { 43 | state.accountIsSecurity = security 44 | }, 45 | /* 账户login验证 */ 46 | [types.DECIDE_ACCOUNT_DECIDEACCOUNT](state) { 47 | 48 | }, 49 | /* 接口数据 */ 50 | [types.UPDATE_DROPDOWN_DROPDOWNDATA](state, data) { 51 | state.dropDownData = data 52 | }, 53 | [types.UPDATE_DROPDOWN_DROPDOWNCOUNT](state, count) { 54 | state.dropDownCount = count 55 | }, 56 | [types.UPDATE_BOXCONTENT_BOXCONTENT](state, dropDownBoxContent) { 57 | state.dropDownBoxContent = dropDownBoxContent 58 | } 59 | } 60 | 61 | 62 | export default mutations 63 | -------------------------------------------------------------------------------- /swagger-vue/src/store/mutations_types.js: -------------------------------------------------------------------------------- 1 | export const SET_DEBUGREQUEST_COUNT = 'SET_DEBUGREQUEST_COUNT' 2 | export const SET_DEBUGREQUEST_RESPONSE = 'SET_DEBUGREQUEST_RESPONSE' 3 | export const SET_DEBUGREQUEST_REQUESTTIME = 'SET_DEBUGREQUEST_REQUESTTIME' 4 | 5 | export const SET_DEBUGREQUEST_SECRETKEYS = 'SET_DEBUGREQUEST_SECRETKEYS' 6 | 7 | export const SET_DEBUGREQUEST_SECRETKEY = 'SET_DEBUGREQUEST_SECRETKEY' 8 | 9 | // tab页数据 10 | export const SELETE_TABDATA_INFODATAITEM = 'SELETE_TABDATA_INFODATAITEM' 11 | export const INSERT_TABDATA_ADDTAB = 'INSERT_TABDATA_ADDTAB' 12 | export const UPDATE_TABDATA_INFODATA = 'UPDATE_TABDATA_INFODATA' 13 | export const DELETE_TABDATA_DELETETAB = 'DELETE_TABDATA_DELETETAB' 14 | export const CLEAR_TABDATA_CLEARTAB = 'CLEAR_TABDATA_CLEARTAB' 15 | export const UPDATE_TABDATA_UPDATETABSHOW = 'UPDATE_TABDATA_UPDATETABSHOW' 16 | // 账号验证 17 | export const DECIDE_ACCOUNT_ISVERIFY = 'DECIDE_ACCOUNT_ISVERIFY' 18 | export const DECIDE_ACCOUNT_DECIDEACCOUNT = 'DECIDE_ACCOUNT_DECIDEACCOUNT' 19 | 20 | // 接口数据 21 | export const UPDATE_DROPDOWN_DROPDOWNDATA = 'UPDATE_DROPDOWN_DROPDOWNDATA' 22 | export const UPDATE_DROPDOWN_DROPDOWNCOUNT = 'UPDATE_DROPDOWN_DROPDOWNCOUNT' 23 | export const UPDATE_BOXCONTENT_BOXCONTENT = 'UPDATE_BOXCONTENT_BOXCONTENT' 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /swagger-vue/src/store/state.js: -------------------------------------------------------------------------------- 1 | const state = { 2 | debugRequestCount: 0, 3 | debugResponse: {}, 4 | debugRequestTime: 0, 5 | debugAuthorizeObj: {}, 6 | debugAuthorization: "", 7 | 8 | tabDataInfo: {}, 9 | tabDataShow: "", 10 | accountIsSecurity: false, 11 | 12 | dropDownData: [], 13 | dropDownCount: 0, 14 | dropDownBoxContent: "" 15 | } 16 | 17 | 18 | export default state 19 | --------------------------------------------------------------------------------