save code
This commit is contained in:
45
generate.go
45
generate.go
@ -10,6 +10,7 @@ package api_doc
|
||||
import (
|
||||
"git.zhangdeman.cn/gateway/api-doc/define"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -149,7 +150,7 @@ type PathItemOperationConfig struct {
|
||||
// &define.UriBaseConfig{
|
||||
// Uri: "/foo/bar",
|
||||
// Method: http.MethodPost,
|
||||
// ContentType: "application/json",
|
||||
// ContentType: ["application/json"],
|
||||
// TagList: []string{"测试标签"},
|
||||
// Summary: "这是一份示例基础配置",
|
||||
// Description: "这是一份示例基础配置",
|
||||
@ -161,3 +162,45 @@ type PathItemOperationConfig struct {
|
||||
func (g *Generate) AddApi(baseCfg *define.UriBaseConfig, paramList []*define.ParamConfig, resultList []*define.ResultConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddComponentsSchema 添加schema
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 15:25 2025/2/8
|
||||
func (g *Generate) AddComponentsSchema(pkgPath string, inputType reflect.Type) {
|
||||
if nil == g.docData.Components {
|
||||
g.docData.Components = &define.Components{
|
||||
Schemas: map[string]*define.Schema{},
|
||||
}
|
||||
}
|
||||
if nil == g.docData.Components.Schemas {
|
||||
g.docData.Components.Schemas = make(map[string]*define.Schema)
|
||||
}
|
||||
if len(pkgPath) == 0 {
|
||||
pkgPath = inputType.PkgPath()
|
||||
}
|
||||
schemaPrefix := ""
|
||||
if "" != pkgPath {
|
||||
schemaPrefix = pkgPath + "."
|
||||
}
|
||||
if inputType.Kind() == reflect.Ptr {
|
||||
inputType = inputType.Elem()
|
||||
}
|
||||
if inputType.Kind() == reflect.Map {
|
||||
// map, 直接添加公共
|
||||
if _, exist := g.docData.Components.Schemas[schemaPrefix+inputType.Name()]; !exist {
|
||||
g.docData.Components.Schemas[schemaPrefix+inputType.Name()] = &define.Schema{
|
||||
Type: consts.SwaggerDataTypeObject,
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
// 数组
|
||||
if inputType.Kind() == reflect.Slice {
|
||||
}
|
||||
// 结构体
|
||||
if inputType.Kind() == reflect.Struct {
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user