add swagger support
parent
0e69c48018
commit
668a26ddbf
|
@ -4,15 +4,16 @@ import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import org.springframework.http.HttpMethod;
|
||||||
import springfox.documentation.builders.PathSelectors;
|
import springfox.documentation.builders.*;
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
import springfox.documentation.service.*;
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.Contact;
|
|
||||||
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.EnableSwagger2;
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 石恒
|
* @Author: 石恒
|
||||||
* @Date: 2023/5/4 20:12
|
* @Date: 2023/5/4 20:12
|
||||||
|
@ -30,7 +31,10 @@ public class SwaggerConfig {
|
||||||
.select()
|
.select()
|
||||||
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
|
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
|
||||||
.paths(PathSelectors.any())
|
.paths(PathSelectors.any())
|
||||||
.build();
|
.build()
|
||||||
|
.globalRequestParameters(getGlobalRequestParameters())
|
||||||
|
.globalResponses(HttpMethod.GET, getGlobalResponseMessage())
|
||||||
|
.globalResponses(HttpMethod.POST, getGlobalResponseMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -43,6 +47,25 @@ public class SwaggerConfig {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加head参数配置
|
||||||
|
*/
|
||||||
|
private List<RequestParameter> getGlobalRequestParameters() {
|
||||||
|
List<RequestParameter> parameters = new ArrayList<>();
|
||||||
|
parameters.add(new RequestParameterBuilder()
|
||||||
|
.name("token")
|
||||||
|
.description("令牌")
|
||||||
|
.required(false)
|
||||||
|
.in(ParameterType.HEADER)
|
||||||
|
.build());
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
private List<Response> getGlobalResponseMessage() {
|
||||||
|
List<Response> responseList = new ArrayList<>();
|
||||||
|
responseList.add(new ResponseBuilder().code("404").description("找不到资源").build());
|
||||||
|
return responseList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue