最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to display in swagger dynamically registered routes in a java webflux applicaiton? - Stack Overflow

programmeradmin3浏览0评论

I am creating a demo applicaiton where I register my endpoints dynamically using an endpoint registrar based on controller beans I have instanciated. Thus there are no annotations for the spring-doc to pick up to register for the swagger and the ui.

I had similarly done the same excercise with a spring-mvc application and I was able to register those controllers using the static method org.springdoc.api.AbstractOpenApiResource.addRestControllers as follows:

@Bean
public OpenAPI api() {

    OpenAPI openAPI = new OpenAPI()

            .addServersItem(new Server().url("/").description("Default Server URL"))
            .info(new Info()
                    .title("DEMO App")
                    .description("Demo Application")
                    .contact(new Contact()
                            .name("Philip G. Nahmias")
                            .email("[email protected]")));


    List<Class> controllers = new ArrayList<>();
    applicationContext.getBeansWithAnnotation(RequestMapping.class).forEach((k, v) -> {
        if (!k.endsWith("ErrorController")) {
            controllers.add(v.getClass());
        }
    });
    addRestControllers(controllers.toArray(new Class[0]));
    return openAPI;
}

But this approach does not work for the reactive application, and I wanted to ask if there some similar approach I could use?

For reference here is an example endpoint I have defined which has all the relevant swagger annotations:

@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Post Request")
@ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "Made request:", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)),
        @ApiResponse(responseCode = "500", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)),
        @ApiResponse(responseCode = "403", description = "Access Forbidden",
                content = @Content(mediaType = "application/json"))
})
public ResponseEntity<String> testPost() {
    return ResponseEntity.ok("ok");
}
发布评论

评论列表(0)

  1. 暂无评论