knife4j 4.x版本集成springdoc配置swaggerConfig

本文档介绍了如何在Knife4j4.x版本中配置Swagger,包括设置接口文档名称、描述、版本、作者信息以及外部链接,适用于SpringMVC应用。

在knife4j文档中并没有看到4.x版本该如何对swaggerConfig进行配置(配置作者,接口文档名称等),故编写此文以帮助更多的人。
废话少说,直接上代码

package com.lackoxy.wetop.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @projectName: wetop
 * @package: com.lackoxy.wetop.config
 * @className: SwaggerConfig
 * @author: lackoxy
 * @description:
 * @date: 2024/4/19 16:05
 */
@Configuration
@Slf4j
public class SwaggerConfig {
    //配置开源协议
//    private License license() {
//        return new License()
//                .name("MIT") //开源协议种类
//                .url("https://opensource.org/licenses/MIT");
//    }

    private Info info(){
        return new Info()
                .title("xxx接口文档") //接口文档名称
                .description("xxx的接口文档") //描述
                .version("v0.1") //项目版本
                .contact(new Contact()
                        .name("作者") //作者
                        .url("github主页地址") //作者网址,可填写你的github主页
                        .email("email")); //邮箱
//              .license(license()); //开源协议
    }
    //额外信息配置 可配可不配
    private ExternalDocumentation externalDocumentation() {
        return new ExternalDocumentation()
                .description("代码仓库地址")
                .url("xxxx");
    }
    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(info())
                .externalDocs(externalDocumentation());
    }
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值