feat: 文档生成支持配置基础信息
This commit is contained in:
57
generate.go
57
generate.go
@ -25,48 +25,39 @@ import (
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:56 2024/7/22
|
||||
func NewOpenapiDoc(info *define.Info, servers []*define.ServerItem) *Generate {
|
||||
if nil == info {
|
||||
info = &define.Info{
|
||||
func NewOpenapiDoc(ofs ...SetGenerateOption) *Generate {
|
||||
// 初始默认值
|
||||
docCfg := &define.OpenapiDoc{
|
||||
Openapi: consts.SwaggerDocVersion3,
|
||||
Info: &define.Info{
|
||||
Description: "openapi接口文档",
|
||||
Title: "openapi接口文档",
|
||||
TermsOfService: "",
|
||||
Contact: nil,
|
||||
License: nil,
|
||||
Version: "0.0.1",
|
||||
}
|
||||
Contact: &define.Contact{
|
||||
Name: "研发人员(developer)",
|
||||
Url: "",
|
||||
Email: "",
|
||||
},
|
||||
License: &define.License{
|
||||
Name: enums.LicenseApache20,
|
||||
Url: enums.LicenseUrlTable[consts.LicenseApache20],
|
||||
},
|
||||
Version: "0.0.1",
|
||||
},
|
||||
Servers: []*define.ServerItem{},
|
||||
Components: &define.Components{Schemas: map[string]*define.Schema{}},
|
||||
Tags: make([]*define.TagItem, 0),
|
||||
Paths: make(map[string]*define.PathConfig),
|
||||
}
|
||||
if len(info.Version) == 0 {
|
||||
info.Version = "0.0.1"
|
||||
}
|
||||
if nil == info.License {
|
||||
info.License = &define.License{
|
||||
Name: consts.LicenseApache20,
|
||||
Url: consts.LicenseUrlTable[consts.LicenseApache20],
|
||||
}
|
||||
}
|
||||
if nil == info.Contact {
|
||||
info.Contact = &define.Contact{
|
||||
Name: "研发人员(developer)",
|
||||
Url: "",
|
||||
Email: "",
|
||||
}
|
||||
}
|
||||
if nil == servers {
|
||||
servers = []*define.ServerItem{}
|
||||
|
||||
for _, option := range ofs {
|
||||
option(docCfg)
|
||||
}
|
||||
return &Generate{
|
||||
readMethodList: []string{
|
||||
http.MethodGet, http.MethodHead, http.MethodConnect, http.MethodOptions, http.MethodTrace,
|
||||
},
|
||||
docData: &define.OpenapiDoc{
|
||||
Openapi: consts.SwaggerDocVersion3,
|
||||
Info: info,
|
||||
Servers: servers,
|
||||
Components: &define.Components{Schemas: map[string]*define.Schema{}},
|
||||
Tags: make([]*define.TagItem, 0),
|
||||
Paths: make(map[string]*define.PathConfig),
|
||||
},
|
||||
docData: docCfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user