基础schema生成

This commit is contained in:
2025-02-10 11:15:29 +08:00
parent 88715a7d56
commit 99a84d8083
3 changed files with 28 additions and 10 deletions

View File

@ -9,6 +9,7 @@ package api_doc
import (
"errors"
"fmt"
"git.zhangdeman.cn/gateway/api-doc/define"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/wrapper"
@ -186,8 +187,8 @@ func (g *Generate) AddApiFromInAndOut(baseCfg *define.UriBaseConfig, paramType r
}
// post类解析
defaultPkgPath := wrapper.String(strings.ReplaceAll(strings.TrimLeft(baseCfg.Uri, "/"), "/", "_")).SnakeCaseToCamel()
paramPkgPath := defaultPkgPath + "Param"
resultPkgPath := defaultPkgPath + "Result"
paramPkgPath := defaultPkgPath + baseCfg.Method + "Param"
resultPkgPath := defaultPkgPath + baseCfg.Method + "Result"
g.AddComponentsSchema(paramPkgPath, paramType)
g.AddComponentsSchema(resultPkgPath, resultType)
if _, exist := g.docData.Paths[baseCfg.Uri]; !exist {
@ -206,16 +207,30 @@ func (g *Generate) AddApiFromInAndOut(baseCfg *define.UriBaseConfig, paramType r
Content: map[string]*define.Media{},
Ref: "",
},
Responses: nil,
Responses: map[string]*define.Response{
fmt.Sprintf("%v", http.StatusOK): &define.Response{
Content: map[string]*define.Media{},
},
},
Callbacks: nil,
Deprecated: false,
Security: nil,
Servers: nil,
}
for _, itemOutputType := range baseCfg.OutputContentType {
cfg.RequestBody.Content[itemOutputType] = &define.Media{
for _, itemType := range baseCfg.ContentType {
cfg.RequestBody.Content[itemType] = &define.Media{
Schema: &define.Schema{
Ref: g.getSchemaRes(paramPkgPath + "." + paramType.Name()),
Ref: g.getSchemaRes(paramPkgPath),
},
Example: "",
Examples: nil,
Encoding: nil,
}
}
for _, itemOutputType := range baseCfg.OutputContentType {
cfg.Responses[fmt.Sprintf("%v", http.StatusOK)].Content[itemOutputType] = &define.Media{
Schema: &define.Schema{
Ref: g.getSchemaRes(resultPkgPath),
},
Example: "",
Examples: nil,