diff --git a/pkg/ffapi/openapi3.go b/pkg/ffapi/openapi3.go index 262d179..cb975ea 100644 --- a/pkg/ffapi/openapi3.go +++ b/pkg/ffapi/openapi3.go @@ -116,7 +116,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 } @@ -394,7 +394,7 @@ func (sg *SwaggerGen) addRoute(ctx context.Context, doc *openapi3.T, route *Rout } else { routeDescription = i18n.Expand(ctx, route.Description) if routeDescription == "" && sg.options.PanicOnMissingDescription { - log.Panicf(i18n.NewError(ctx, i18n.MsgRouteDescriptionMissing, route.Name).Error()) + log.Panicf("%s", i18n.NewError(ctx, i18n.MsgRouteDescriptionMissing, route.Name).Error()) } } op := &openapi3.Operation{ diff --git a/pkg/ffapi/openapi3_test.go b/pkg/ffapi/openapi3_test.go index f44911a..bd58883 100644 --- a/pkg/ffapi/openapi3_test.go +++ b/pkg/ffapi/openapi3_test.go @@ -19,10 +19,11 @@ package ffapi import ( "context" "fmt" - "github.com/stretchr/testify/require" "net/http" "testing" + "github.com/stretchr/testify/require" + "github.com/getkin/kin-openapi/openapi3" "github.com/ghodss/yaml" "github.com/hyperledger/firefly-common/pkg/config" @@ -268,6 +269,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{ {