feat: 修复响应数据文档生成的BUG
This commit is contained in:
@@ -167,8 +167,23 @@ func (g *Generate) AddApiDoc(apiMeta define.UriConfig, request any, response any
|
||||
apiOperate.RequestBody = &openapi3.RequestBodyRef{
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Ref: requestTypeStr,
|
||||
Value: nil,
|
||||
Ref: "",
|
||||
Value: &openapi3.RequestBody{
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Description: "",
|
||||
Required: false,
|
||||
Content: map[string]*openapi3.MediaType{
|
||||
consts.MimeTypeJson: {
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Schema: schemaData,
|
||||
Example: nil,
|
||||
Examples: nil,
|
||||
Encoding: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +191,7 @@ func (g *Generate) AddApiDoc(apiMeta define.UriConfig, request any, response any
|
||||
if _, exist := g.doc.Components.Schemas[requestTypeStr]; !exist {
|
||||
g.doc.Components.Schemas[requestTypeStr] = schemaData
|
||||
}
|
||||
responseTypeStr := requestType.String()
|
||||
responseTypeStr := responseType.String()
|
||||
if _, exist := g.doc.Components.Schemas[responseTypeStr]; !exist {
|
||||
g.doc.Components.Schemas[responseTypeStr] = GenerateOpenAPISchema(responseType)
|
||||
}
|
||||
@@ -213,7 +228,7 @@ func (g *Generate) initApiConfig(apiMeta define.UriConfig) (*openapi3.Operation,
|
||||
Extensions: nil,
|
||||
Origin: nil,
|
||||
Ref: "",
|
||||
Summary: "",
|
||||
Summary: apiMeta.Desc,
|
||||
Description: "",
|
||||
Connect: nil,
|
||||
Delete: nil,
|
||||
|
||||
@@ -40,6 +40,12 @@ func TestGenerate_AddApiDoc(t *testing.T) {
|
||||
TagList: []string{"test"},
|
||||
Desc: "测试接口",
|
||||
}, Category{}, Product{})
|
||||
instance.AddApiDoc(define.UriConfig{
|
||||
Path: "/a/b/c",
|
||||
RequestMethod: http.MethodPost,
|
||||
TagList: []string{"test"},
|
||||
Desc: "测试接口",
|
||||
}, Category{}, Product{})
|
||||
// 输出 JSON
|
||||
data, _ := json.MarshalIndent(instance.doc, "", " ")
|
||||
fmt.Println(string(data))
|
||||
|
||||
Reference in New Issue
Block a user