diff --git a/openapi/generate.go b/openapi/generate.go index bd5503a..eb89637 100644 --- a/openapi/generate.go +++ b/openapi/generate.go @@ -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, diff --git a/openapi/generate_test.go b/openapi/generate_test.go index 2b93cd5..e4b84f6 100644 --- a/openapi/generate_test.go +++ b/openapi/generate_test.go @@ -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))