Ich hatte die gleiche Übung auf ähnliche Weise mit einer Spring-MVC-Anwendung durchgeführt und war dazu in der Lage um diese Controller mit der statischen Methode org.springdoc.api.AbstractOpenApiResource.addRestControllers wie folgt zu registrieren:
Code: Select all
@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("nahmias22@gmail.com")));
List 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;
}
Hier als Referenz ist ein von mir definierter Beispielendpunkt, der alle relevanten Swagger-Anmerkungen enthält:
Code: Select all
@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 testPost() {
return ResponseEntity.ok("ok");
}