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");
}