parent
800381c290
commit
a7856e4f84
@ -0,0 +1,27 @@
|
||||
package com.luoo.music.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
|
||||
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
import swagger.BaseSwaggerConfig;
|
||||
import swagger.SwaggerProperties;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@EnableSwaggerBootstrapUI
|
||||
public class SwaggerConfig extends BaseSwaggerConfig {
|
||||
|
||||
@Override
|
||||
public SwaggerProperties swaggerProperties() {
|
||||
return SwaggerProperties.builder()
|
||||
.apiBasePackage("com.luoo.music.controller")
|
||||
.title("luoo-music API")
|
||||
.description("luoo-music 后端接口文档")
|
||||
.contactName("locust")
|
||||
.version("1.0")
|
||||
.enableSecurity(false)
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.luoo.music.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
||||
@Override
|
||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
super.addResourceHandlers(registry);
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package com.luoo.user.swagger;
|
||||
package com.luoo.user.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
|
||||
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
import swagger.BaseSwaggerConfig;
|
||||
import swagger.SwaggerProperties;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
@ -1,58 +0,0 @@
|
||||
package com.luoo.user.swagger;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.builders.ResponseMessageBuilder;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.*;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseSwaggerConfig {
|
||||
|
||||
@Bean
|
||||
@Order(value = 1)
|
||||
public Docket createRestApi() {
|
||||
List<ResponseMessage> responseMessageList =new ArrayList<>();
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(200).message("成功").responseModel(new ModelRef("成功")).build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(20001).message("失败").responseModel(new ModelRef("失败")).build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(20002).message("用户名或密码错误").responseModel(new ModelRef("用户名或密码错误")).build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(20003).message("无权访问").responseModel(new ModelRef("无权访问")).build());
|
||||
responseMessageList.add(new ResponseMessageBuilder().code(20009).message("重复提交").responseModel(new ModelRef("重复提交")).build());
|
||||
SwaggerProperties swaggerProperties = swaggerProperties();
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.globalResponseMessage(RequestMethod.GET, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.POST, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
|
||||
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
|
||||
.apiInfo(apiInfo(swaggerProperties))
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
|
||||
//.apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
|
||||
return new ApiInfoBuilder()
|
||||
.title(swaggerProperties.getTitle())
|
||||
.description(swaggerProperties.getDescription())
|
||||
.contact(new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(), swaggerProperties.getContactEmail()))
|
||||
.version(swaggerProperties.getVersion())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义Swagger配置
|
||||
*/
|
||||
public abstract SwaggerProperties swaggerProperties();
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.luoo.user.swagger;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Swagger自定义配置
|
||||
* Created by macro on 2020/7/16.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Builder
|
||||
public class SwaggerProperties {
|
||||
/**
|
||||
* API文档生成基础路径
|
||||
*/
|
||||
private String apiBasePackage;
|
||||
/**
|
||||
* 是否要启用登录认证
|
||||
*/
|
||||
private boolean enableSecurity;
|
||||
/**
|
||||
* 文档标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 文档描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 文档版本
|
||||
*/
|
||||
private String version;
|
||||
/**
|
||||
* 文档联系人姓名
|
||||
*/
|
||||
private String contactName;
|
||||
/**
|
||||
* 文档联系人网址
|
||||
*/
|
||||
private String contactUrl;
|
||||
/**
|
||||
* 文档联系人邮箱
|
||||
*/
|
||||
private String contactEmail;
|
||||
}
|
Loading…
Reference in new issue