繁体   English   中英

昂首阔步无法识别api描述

[英]swagger doesn't recognize api description

我instatiate docket这样

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.config.internal"))
        .paths(Predicates.or(PathSelectors.ant("/api**/**")))
        .build();
}

我创建了一组存根端点,它们模拟了/login/oauth的真实端点。

@Api("Authentication")
@RequestMapping("/api")
public interface LoginEndpointApi {

    @ApiOperation(value = "Github SSO endpoint", notes = "Endpoint for Github SSO authentication")
    @ApiResponses({
        @ApiResponse(code = 200, message = "HTML page of main application")
    })
    @GetMapping("/oauth/github")
    default void oauthGithub() {
        throw new UnsupportedOperationException();
    }

    @ApiOperation(value = "Get CSRF token", notes = "Returns current CSRF token")
    @ApiResponses({
        @ApiResponse(code = 200, message = "CSRF token response", response = String.class,
            examples = @Example({@ExampleProperty(value = "015275eb-293d-4ce9-ba07-ff5e1c348092")}))
    })
    @GetMapping("/csrf-token")
    default void csrfToken() {
        throw new UnsupportedOperationException();
    }

    @ApiOperation(value = "Login endpoint", notes = "Login endpoint for authorization")
    @ApiResponses({
        @ApiResponse(code = 200, message = "Successful authentication")
    })
    @PostMapping("/login")
    default void login(
            @ApiParam(required = true, name = "login", value = "login body")
            @RequestBody LoginRequest loginRequest) {
        throw new UnsupportedOperationException();
    }
}

但是它不认识它。 它与我描述的位于com.config.internal包中。

但是页面swagger ui为空,表明No operations defined in spec!

问题是什么?

如果要为上述指定的请求映射提供全面的文档,则可以使用.paths(Predicates.or(PathSelectors.ant("/api/**")))路径匹配器对其进行简单描述。 但是,如果您的路径包含更复杂的内容(例如api + text without backslash separator那么您应该使用https://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/util/AntPathMatcher知道html的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM