英文:
How to display "/oauth/token" endpoint on swagger-ui?
问题
@EnableSwagger2
@Configuration
public class SwaggerConfiguration {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("all").select()
.apis(RequestHandlerSelectors.basePackage("com.demo.userservice.api.controller"))
.paths(regex("/api.*"))
.build()
.apiInfo(metaInfo());
}
private ApiInfo metaInfo() {
ApiInfo apiInfo = new ApiInfo(
"Spring Boot Swagger USERSERVICE API",
"Spring Boot Swagger USERSERVICE API",
"1.0",
"Terms of Service",
new Contact("userservice", "",
""),
"Apache License Version 2.0",
"https://www.apache.org/licesen.html", new ArrayList<VendorExtension>()
);
return apiInfo;
}
}
英文:
My project use spring cloud oauth to authenticate user with "/oauth/token" endpoint, but i can't find any way to display this api operation on swagger ui. What should I do?
Swagger Configuration:
@EnableSwagger2
@Configuration
public class SwaggerConfiguration {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("all").select()
.apis(RequestHandlerSelectors.basePackage("com.demo.userservice.api.controller"))
.paths(regex("/api.*"))
.build()
.apiInfo(metaInfo());
}
private ApiInfo metaInfo() {
ApiInfo apiInfo = new ApiInfo(
"Spring Boot Swagger USERSERVICE API",
"Spring Boot Swagger USERSERVICE API",
"1.0",
"Terms of Service",
new Contact("userservice", "",
""),
"Apache License Version 2.0",
"https://www.apache.org/licesen.html", new ArrayList<VendorExtension>()
);
return apiInfo;
}
}
答案1
得分: 1
一种解决方案是打开所有终端以显示oauth/token
终端,方法如下:
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build().pathMapping("/");
或者
如果您只想显示所需路径,例如/api/.*
,则可以使用以下方式修改oauth终端的端点:
@Configuration
@EnableAuthorizationServer
public class EndPointModificationConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
endpoints
.pathMapping("/oauth/token", "/api/oauth/token");
}
}
并且使用以下代码获取所有API:
.apis(RequestHandlerSelectors.any())
英文:
One solution is open all endpoint to show oauth/token
endpoint this way
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build().pathMapping("/")
Or
If you want to show only desired path like /api/.*
then you can modify the endpoint of oauth using this
@Configuration
@EnableAuthorizationServer
public class EndPointModificationConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
endpoints
.pathMapping("/oauth/token", "/api/oauth/token");
}
}
And use this for get all api
.apis(RequestHandlerSelectors.any())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论