如何在Springfox Swagger UI中配置标题,描述和许可证?

时间:2017-09-11 10:48:51

标签: spring spring-boot swagger swagger-ui springfox

当您在Spring Boot应用程序中使用Springfox启动Swagger UI时,它看起来像这样:

enter image description here

如何配置标题和说明(" Api文档")和许可证(Apache 2.0)。

2 个答案:

答案 0 :(得分:4)

您可以通过将ApiInfo对象传递到您的文档来设置这些值。

new Docket(DocumentationType.SWAGGER_2)
    ...
    .apiInfo(new ApiInfo(...))
    ...

ApiInfo的构造函数接受有关API的若干详细信息。在这种情况下,您应该查看标题,说明和许可证参数。

答案 1 :(得分:0)

Swagger 配置类(Spring 启动):

@Configuration
public class SpringFoxConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Demo Test API")
                .description("Demo test API task")
                .license("© 2021 by my")
                .build();
    }

}