feat: 文档生成支持配置基础信息
This commit is contained in:
95
geerate_option.go
Normal file
95
geerate_option.go
Normal file
@ -0,0 +1,95 @@
|
||||
// Package api_doc ...
|
||||
//
|
||||
// Description : api_doc ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2025-08-23 09:30
|
||||
package api_doc
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"git.zhangdeman.cn/gateway/api-doc/enums"
|
||||
)
|
||||
|
||||
// SetGenerateOption 设置文档生成选项
|
||||
type SetGenerateOption func(opt *define.OpenapiDoc)
|
||||
|
||||
// generateOption 生成文档的一些配置选项
|
||||
type generateOption struct {
|
||||
license enums.License // 文档的license
|
||||
description string // 文档的描述
|
||||
title string // 文档的标题
|
||||
}
|
||||
|
||||
// WithDocLicense 设置文档协议名称 + 协议链接
|
||||
func WithDocLicense(l enums.License) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
if l == "" {
|
||||
return
|
||||
}
|
||||
opt.Info.License.Name = l
|
||||
opt.Info.License.Url = enums.LicenseUrlTable[l]
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocDescription 设置文档描述
|
||||
func WithDocDescription(desc string) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
if desc == "" {
|
||||
return
|
||||
}
|
||||
opt.Info.Description = desc
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocTitle 设置文档标题
|
||||
func WithDocTitle(title string) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
if len(title) == 0 {
|
||||
return
|
||||
}
|
||||
opt.Info.Title = title
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocVersion 设置文档版本
|
||||
func WithDocVersion(version string) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
opt.Info.Version = version
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocContactName 设置文档联系人名称
|
||||
func WithDocContactName(name string) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
if name == "" {
|
||||
return
|
||||
}
|
||||
opt.Info.Contact.Name = name
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocContactEmail 设置文档联系人邮箱
|
||||
func WithDocContactEmail(email string) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
opt.Info.Contact.Email = email
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocContactHomePage 设置文档联系人主页
|
||||
func WithDocContactHomePage(url string) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
opt.Info.Contact.Url = url
|
||||
}
|
||||
}
|
||||
|
||||
// WithDocServers 设置文档服务器列表
|
||||
func WithDocServers(serverList []*define.ServerItem) SetGenerateOption {
|
||||
return func(opt *define.OpenapiDoc) {
|
||||
if len(serverList) == 0 {
|
||||
return
|
||||
}
|
||||
opt.Servers = serverList
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user