1+ package com .config ;
2+ import com .mangofactory .swagger .configuration .SpringSwaggerConfig ;
3+ import com .mangofactory .swagger .models .dto .ApiInfo ;
4+ import com .mangofactory .swagger .paths .SwaggerPathProvider ;
5+ import com .mangofactory .swagger .plugin .EnableSwagger ;
6+ import com .mangofactory .swagger .plugin .SwaggerSpringMvcPlugin ;
7+ import org .springframework .beans .factory .annotation .Autowired ;
8+ import org .springframework .context .annotation .Bean ;
9+ import org .springframework .context .annotation .ComponentScan ;
10+ import org .springframework .context .annotation .Configuration ;
11+ import org .springframework .web .servlet .config .annotation .DefaultServletHandlerConfigurer ;
12+ import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
13+ import org .springframework .web .servlet .config .annotation .WebMvcConfigurerAdapter ;
14+
15+ @ Configuration
16+ @ EnableWebMvc
17+ @ EnableSwagger
18+ @ ComponentScan (basePackages ={"com.youmeek.ssm.module.user.controller" })
19+ public class MySwaggerConfig extends WebMvcConfigurerAdapter {
20+ private SpringSwaggerConfig springSwaggerConfig ;
21+
22+ @ Autowired
23+ public void setSpringSwaggerConfig (SpringSwaggerConfig springSwaggerConfig ) {
24+ this .springSwaggerConfig = springSwaggerConfig ;
25+ }
26+ /**
27+ * 链式编程 来定制API样式
28+ * 后续会加上分组信息
29+ * @return
30+ */
31+ @ Bean
32+ public SwaggerSpringMvcPlugin customImplementation (){
33+ return new SwaggerSpringMvcPlugin (this .springSwaggerConfig )
34+ .apiInfo (apiInfo ())
35+ .includePatterns (".*" )
36+ // .pathProvider(new GtPaths())
37+ .apiVersion ("0.0.1" )
38+ .swaggerGroup ("user" );
39+ }
40+ private ApiInfo apiInfo () {
41+ ApiInfo apiInfo = new ApiInfo (
42+ "bugkillers-back API" ,
43+ "bugkillers 后台API文档" ,
44+ "<a href='http://127.0.0.1:9081/api' '='' style='color: rgb(59, 115, 175); text-decoration: none; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; background: none !important;'>http://127.0.0.1:9081/api" ,
45+ "bugkillers@163.com" ,
46+ "My License" ,
47+ "My Apps API License URL" );
48+ return apiInfo ;
49+ }
50+ @ Override
51+ public void configureDefaultServletHandling (DefaultServletHandlerConfigurer configurer ) {
52+ configurer .enable ();
53+ }
54+
55+ class GtPaths extends SwaggerPathProvider {
56+ @ Override
57+ protected String applicationPath () {
58+ return "/restapi" ;
59+ }
60+ @ Override
61+ protected String getDocumentationPath () {
62+ return "/restapi" ;
63+ }
64+ }
65+
66+ }
0 commit comments