问题
While I am trying to integrate Swagger into a very simple Spring Boot REST app, Swagger-UI.html won't display and pick up my customized API Info. How should I make changes to below code so Swagger UI page will display the customized API Information? I cannot debug the SwaggerConfig class as well, put breakpoints in but when run as Spring Boot app, breakpoints won't stop.
What I have in pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
My SwaggerConfig Class:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket messageApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("cool-report-api")
.apiInfo(apiInfo())
.select()
.paths(messageApiPaths()).build();
}
private Predicate<String> messageApiPaths() {
return or(regex("/api/topics.*"), regex("/api/message.*"));
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Cool Message Receiver API")
.description("Cool Message Receiver REST API Reference")
.termsOfServiceUrl("http://www.cool-message-receiver.com")
.contact(new Contact("John Smith", null, "john.smith@cool.com"))
.license("Cool Proprietary Software")
.licenseUrl("www.cool-message.com")
.version("0.1.0")
.build();
}
}
But after I spring-boot:run the above code, the customized API Info doesn't seem to work and Swagger still displays the default “Api Documentation” title and "Apache 2.0" license etc. Here is what I am seeing now:
回答1:
I think the problem is the messageApisPath().
Make sure you add the following library:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
It contains a lot of predicate functions. Make sure your 'or' is coming from there.
The following works for me
private Predicate<String> messageApiPaths() {
return Predicates.or(PathSelectors.regex("/api/topics.*"), PathSelectors.regex("/api/message.*"));
}
Thanks
来源:https://stackoverflow.com/questions/47742734/swagger-doesnt-pick-up-customized-api-info-and-always-shows-default-values