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{
|
apiOperate.RequestBody = &openapi3.RequestBodyRef{
|
||||||
Extensions: nil,
|
Extensions: nil,
|
||||||
Origin: nil,
|
Origin: nil,
|
||||||
Ref: requestTypeStr,
|
Ref: "",
|
||||||
Value: nil,
|
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 {
|
if _, exist := g.doc.Components.Schemas[requestTypeStr]; !exist {
|
||||||
g.doc.Components.Schemas[requestTypeStr] = schemaData
|
g.doc.Components.Schemas[requestTypeStr] = schemaData
|
||||||
}
|
}
|
||||||
responseTypeStr := requestType.String()
|
responseTypeStr := responseType.String()
|
||||||
if _, exist := g.doc.Components.Schemas[responseTypeStr]; !exist {
|
if _, exist := g.doc.Components.Schemas[responseTypeStr]; !exist {
|
||||||
g.doc.Components.Schemas[responseTypeStr] = GenerateOpenAPISchema(responseType)
|
g.doc.Components.Schemas[responseTypeStr] = GenerateOpenAPISchema(responseType)
|
||||||
}
|
}
|
||||||
@@ -213,7 +228,7 @@ func (g *Generate) initApiConfig(apiMeta define.UriConfig) (*openapi3.Operation,
|
|||||||
Extensions: nil,
|
Extensions: nil,
|
||||||
Origin: nil,
|
Origin: nil,
|
||||||
Ref: "",
|
Ref: "",
|
||||||
Summary: "",
|
Summary: apiMeta.Desc,
|
||||||
Description: "",
|
Description: "",
|
||||||
Connect: nil,
|
Connect: nil,
|
||||||
Delete: nil,
|
Delete: nil,
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ func TestGenerate_AddApiDoc(t *testing.T) {
|
|||||||
TagList: []string{"test"},
|
TagList: []string{"test"},
|
||||||
Desc: "测试接口",
|
Desc: "测试接口",
|
||||||
}, Category{}, Product{})
|
}, Category{}, Product{})
|
||||||
|
instance.AddApiDoc(define.UriConfig{
|
||||||
|
Path: "/a/b/c",
|
||||||
|
RequestMethod: http.MethodPost,
|
||||||
|
TagList: []string{"test"},
|
||||||
|
Desc: "测试接口",
|
||||||
|
}, Category{}, Product{})
|
||||||
// 输出 JSON
|
// 输出 JSON
|
||||||
data, _ := json.MarshalIndent(instance.doc, "", " ")
|
data, _ := json.MarshalIndent(instance.doc, "", " ")
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user