diff --git a/pkg/ffapi/openapi3.go b/pkg/ffapi/openapi3.go index 085a88b..e11ed8c 100644 --- a/pkg/ffapi/openapi3.go +++ b/pkg/ffapi/openapi3.go @@ -137,7 +137,7 @@ func (sg *SwaggerGen) getPathItem(doc *openapi3.T, path string) *openapi3.PathIt if doc.Paths == nil { doc.Paths = &openapi3.Paths{} } - pi := doc.Paths.Find(path) + pi := doc.Paths.Value(path) if pi != nil { return pi } diff --git a/pkg/ffapi/openapi3_test.go b/pkg/ffapi/openapi3_test.go index 979cf4e..22ed6af 100644 --- a/pkg/ffapi/openapi3_test.go +++ b/pkg/ffapi/openapi3_test.go @@ -293,6 +293,34 @@ func TestWildcards(t *testing.T) { assert.NotNil(t, swagger.Paths.Value("/namespaces/{ns}/example1/{id}")) } +func TestSamePathWithDifferentValues(t *testing.T) { + routes := []*Route{ + { + Name: "op1", + Path: "namespaces/{ns}/example1/{id}", + Method: http.MethodPost, + JSONInputValue: func() interface{} { return &TestStruct1{} }, + JSONOutputCodes: []int{http.StatusOK}, + }, + { + Name: "op2", + Path: "namespaces/{ns}/example1/{did}", + Method: http.MethodPost, + JSONInputValue: func() interface{} { return &TestStruct1{} }, + JSONOutputCodes: []int{http.StatusOK}, + }, + } + swagger := NewSwaggerGen(&SwaggerGenOptions{ + Title: "UnitTest", + Version: "1.0", + BaseURL: "http://localhost:12345/api/v1", + }).Generate(context.Background(), routes) + assert.Equal(t, 2, swagger.Paths.Len()) + assert.NotNil(t, swagger.Paths.Find("/namespaces/{ns}/example1/{id}")) + assert.NotNil(t, swagger.Paths.Value("/namespaces/{ns}/example1/{id}")) + assert.NotNil(t, swagger.Paths.Find("/namespaces/{ns}/example1/{did}")) + assert.NotNil(t, swagger.Paths.Value("/namespaces/{ns}/example1/{did}")) +} func TestFFExcludeTag(t *testing.T) { routes := []*Route{ {