|
| 1 | +package com.baeldung.swaggerboot.configuration; |
| 2 | + |
| 3 | +import com.fasterxml.classmate.TypeResolver; |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; |
| 5 | +import org.springframework.context.annotation.Bean; |
| 6 | +import org.springframework.context.annotation.ComponentScan; |
| 7 | +import org.springframework.context.annotation.Configuration; |
| 8 | +import springfox.documentation.builders.PathSelectors; |
| 9 | +import springfox.documentation.builders.RequestHandlerSelectors; |
| 10 | +import springfox.documentation.service.ApiInfo; |
| 11 | +import springfox.documentation.service.Contact; |
| 12 | +import springfox.documentation.spi.DocumentationType; |
| 13 | +import springfox.documentation.spring.web.plugins.Docket; |
| 14 | +import springfox.documentation.swagger.web.*; |
| 15 | +import springfox.documentation.swagger2.annotations.EnableSwagger2; |
| 16 | + |
| 17 | +import java.util.Collections; |
| 18 | + |
| 19 | +@Configuration |
| 20 | +@EnableSwagger2 |
| 21 | +@ComponentScan("com.baeldung.swaggerboot.controller") |
| 22 | +public class SpringFoxConfig { |
| 23 | + |
| 24 | + @Autowired |
| 25 | + private TypeResolver typeResolver; |
| 26 | + |
| 27 | + private ApiInfo apiInfo() { |
| 28 | + return new ApiInfo( |
| 29 | + "My REST API", |
| 30 | + "Some custom description of API.", |
| 31 | + "API TOS", |
| 32 | + "Terms of service", |
| 33 | + new Contact("John Doe", "www.example.com", "myeaddress@company.com"), |
| 34 | + "License of API", |
| 35 | + "API license URL", |
| 36 | + Collections.emptyList()); |
| 37 | + } |
| 38 | + |
| 39 | + @Bean |
| 40 | + public Docket api() { |
| 41 | + return new Docket(DocumentationType.SWAGGER_2) |
| 42 | + .apiInfo(apiInfo()) |
| 43 | + .select() |
| 44 | + .apis(RequestHandlerSelectors.any()) |
| 45 | + .paths(PathSelectors.any()) |
| 46 | + .build(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * SwaggerUI information |
| 51 | + */ |
| 52 | + |
| 53 | + @Bean |
| 54 | + UiConfiguration uiConfig() { |
| 55 | + return UiConfigurationBuilder.builder() |
| 56 | + .deepLinking(true) |
| 57 | + .displayOperationId(false) |
| 58 | + .defaultModelsExpandDepth(1) |
| 59 | + .defaultModelExpandDepth(1) |
| 60 | + .defaultModelRendering(ModelRendering.EXAMPLE) |
| 61 | + .displayRequestDuration(false) |
| 62 | + .docExpansion(DocExpansion.NONE) |
| 63 | + .filter(false) |
| 64 | + .maxDisplayedTags(null) |
| 65 | + .operationsSorter(OperationsSorter.ALPHA) |
| 66 | + .showExtensions(false) |
| 67 | + .tagsSorter(TagsSorter.ALPHA) |
| 68 | + .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS) |
| 69 | + .validatorUrl(null) |
| 70 | + .build(); |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments