如何在 swagger-ui 上显示“/oauth/token”端点?

How to display "/oauth/token" endpoint on swagger-ui?

我的项目使用 spring 云 oauth 通过“/oauth/token”端点对用户进行身份验证,但我找不到任何方法来显示此 api 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;
}


}

一个解决方案是打开所有端点以这种方式显示 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())