记得上下班打卡 | git大法好,push需谨慎

Commit 61e7d54a authored by 张国柄's avatar 张国柄

调整Swagger.API响应状态;

parent 0f16eee2
...@@ -6,24 +6,48 @@ import org.springframework.context.annotation.Bean; ...@@ -6,24 +6,48 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo; import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact; import springfox.documentation.service.Contact;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import java.util.ArrayList;
import java.util.List;
@Configuration @Configuration
@EnableSwagger2WebMvc @EnableSwagger2WebMvc
public class Swagger2Config { public class Swagger2Config {
@Autowired @Autowired
private Environment environment; private Environment environment;
List<ResponseMessage> responseMessageList = new ArrayList<ResponseMessage>() {
private static final long serialVersionUID = -5089595359417116101L;
{
// add(
// new ResponseMessageBuilder().code(HttpStatus.INTERNAL_SERVER_ERROR.value()).message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
// .responseModel(new ModelRef(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()))
// .build()
// );
}
};
@Bean @Bean
public Docket createRestApi() { public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.globalResponseMessage(RequestMethod.GET, responseMessageList)
.globalResponseMessage(RequestMethod.HEAD, responseMessageList)
.globalResponseMessage(RequestMethod.POST, responseMessageList)
.globalResponseMessage(RequestMethod.PUT, responseMessageList)
.globalResponseMessage(RequestMethod.PATCH, responseMessageList)
.globalResponseMessage(RequestMethod.DELETE, responseMessageList)
.globalResponseMessage(RequestMethod.OPTIONS, responseMessageList)
.globalResponseMessage(RequestMethod.TRACE, responseMessageList)
.apiInfo(apiInfo()) .apiInfo(apiInfo())
.select() .select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
...@@ -36,9 +60,9 @@ public class Swagger2Config { ...@@ -36,9 +60,9 @@ public class Swagger2Config {
return new ApiInfoBuilder() return new ApiInfoBuilder()
.title((StringUtils.isEmpty(appName) ? "service-xxx" : appName.substring(10)) + " APIs") .title((StringUtils.isEmpty(appName) ? "service-xxx" : appName.substring(10)) + " APIs")
.description(appName) .description(appName)
.contact(new Contact("lightnet", "", "**@lightnet.io")) .contact(new Contact("lightnet", "", "**@zhengzai.tv"))
.version("all") .version("all")
.termsOfServiceUrl("xxx.xxx.xxx") .termsOfServiceUrl("xxx.zhengzai.tv/xxx")
.build(); .build();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment