SwaggerConfig.java (1456B)
1 package com.wimdupont.swagger.blueprint.config; 2 3 import io.swagger.v3.oas.models.OpenAPI; 4 import io.swagger.v3.oas.models.info.Info; 5 import org.slf4j.Logger; 6 import org.slf4j.LoggerFactory; 7 import org.springdoc.core.models.GroupedOpenApi; 8 import org.springframework.context.annotation.Bean; 9 import org.springframework.context.annotation.Configuration; 10 11 import java.io.File; 12 import java.io.IOException; 13 import java.net.URL; 14 import java.nio.file.Files; 15 16 @Configuration 17 public class SwaggerConfig { 18 private static final String DOCUMENTATION_FILE = "documentation.md"; 19 private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerConfig.class); 20 21 @Bean 22 public OpenAPI getOpenAPI() { 23 return new OpenAPI() 24 .info(getInfo()); 25 } 26 27 private Info getInfo() { 28 Info info = new Info().title("Blueprint") 29 .version("v1"); 30 31 URL url = getClass().getClassLoader().getResource(DOCUMENTATION_FILE); 32 if (url != null) { 33 try { 34 info.description(new String(Files.readAllBytes(new File(url.getFile()).toPath()))); 35 } catch (IOException e) { 36 LOGGER.error(e.getMessage(), e); 37 } 38 } 39 return info; 40 } 41 42 @Bean 43 public GroupedOpenApi overviewGroupedOpenApi() { 44 return GroupedOpenApi.builder() 45 .group("overview") 46 .pathsToMatch("/**") 47 .build(); 48 } 49 50 }