From 73e4a69383a4873a7dd09aee3c0fbe8475d95ead Mon Sep 17 00:00:00 2001 From: John Guo Date: Fri, 8 Oct 2021 14:44:10 +0800 Subject: [PATCH] openapi --- protocol/goai/goai_path.go | 4 ++++ protocol/goai/goai_shema.go | 6 ++++++ protocol/goai/goai_test.go | 10 +++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/protocol/goai/goai_path.go b/protocol/goai/goai_path.go index 6fa73d224..35fc38282 100644 --- a/protocol/goai/goai_path.go +++ b/protocol/goai/goai_path.go @@ -110,6 +110,10 @@ func (oai *OpenApiV3) addPath(in addPathInput) error { ) } + if v, ok := oai.Paths[in.Path]; ok { + path = v + } + // Method check. if in.Method == "" { in.Method = gmeta.Get(inputObject.Interface(), TagNameMethod).String() diff --git a/protocol/goai/goai_shema.go b/protocol/goai/goai_shema.go index 6d2d61aef..73de2aaae 100644 --- a/protocol/goai/goai_shema.go +++ b/protocol/goai/goai_shema.go @@ -131,6 +131,12 @@ func (oai *OpenApiV3) golangTypeToOAIType(t reflect.Type) string { return TypeString case reflect.Struct: + switch t.String() { + case + `time.Time`, + `gtime.Time`: + return TypeString + } return TypeObject case reflect.Slice, reflect.Array: diff --git a/protocol/goai/goai_test.go b/protocol/goai/goai_test.go index f143cbe13..5dd333630 100644 --- a/protocol/goai/goai_test.go +++ b/protocol/goai/goai_test.go @@ -99,7 +99,7 @@ func TestOpenApiV3_Add(t *testing.T) { t.AssertNil(err) err = oai.Add(goai.AddInput{ - Path: "/test2/{appId}", + Path: "/test1/{appId}", Method: goai.HttpMethodPost, Object: f, }) @@ -116,13 +116,13 @@ func TestOpenApiV3_Add(t *testing.T) { t.Assert(oai.Components.Schemas[`goai_test.SetSpecInfo`].Value.Properties[`Params`].Value.Type, goai.TypeArray) // Paths. - t.Assert(len(oai.Paths), 2) + t.Assert(len(oai.Paths), 1) t.AssertNE(oai.Paths[`/test1/{appId}`].Put, nil) t.Assert(len(oai.Paths[`/test1/{appId}`].Put.Tags), 1) t.Assert(len(oai.Paths[`/test1/{appId}`].Put.Parameters), 2) - t.AssertNE(oai.Paths[`/test2/{appId}`].Post, nil) - t.Assert(len(oai.Paths[`/test2/{appId}`].Post.Tags), 1) - t.Assert(len(oai.Paths[`/test2/{appId}`].Post.Parameters), 2) + t.AssertNE(oai.Paths[`/test1/{appId}`].Post, nil) + t.Assert(len(oai.Paths[`/test1/{appId}`].Post.Tags), 1) + t.Assert(len(oai.Paths[`/test1/{appId}`].Post.Parameters), 2) }) }