Skip to content

Commit 1bb155a

Browse files
authored
Merge pull request #145 from dwertent/fix-swagger-gen
fix: change SwaggerGen to support multiple values with the same path
2 parents 426c823 + 51cc5a7 commit 1bb155a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pkg/ffapi/openapi3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (sg *SwaggerGen) getPathItem(doc *openapi3.T, path string) *openapi3.PathIt
137137
if doc.Paths == nil {
138138
doc.Paths = &openapi3.Paths{}
139139
}
140-
pi := doc.Paths.Find(path)
140+
pi := doc.Paths.Value(path)
141141
if pi != nil {
142142
return pi
143143
}

pkg/ffapi/openapi3_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,34 @@ func TestWildcards(t *testing.T) {
308308
assert.NotNil(t, swagger.Paths.Value("/namespaces/{ns}/example1/{id}"))
309309
}
310310

311+
func TestSamePathWithDifferentValues(t *testing.T) {
312+
routes := []*Route{
313+
{
314+
Name: "op1",
315+
Path: "namespaces/{ns}/example1/{id}",
316+
Method: http.MethodPost,
317+
JSONInputValue: func() interface{} { return &TestStruct1{} },
318+
JSONOutputCodes: []int{http.StatusOK},
319+
},
320+
{
321+
Name: "op2",
322+
Path: "namespaces/{ns}/example1/{did}",
323+
Method: http.MethodPost,
324+
JSONInputValue: func() interface{} { return &TestStruct1{} },
325+
JSONOutputCodes: []int{http.StatusOK},
326+
},
327+
}
328+
swagger := NewSwaggerGen(&SwaggerGenOptions{
329+
Title: "UnitTest",
330+
Version: "1.0",
331+
BaseURL: "http://localhost:12345/api/v1",
332+
}).Generate(context.Background(), routes)
333+
assert.Equal(t, 2, swagger.Paths.Len())
334+
assert.NotNil(t, swagger.Paths.Find("/namespaces/{ns}/example1/{id}"))
335+
assert.NotNil(t, swagger.Paths.Value("/namespaces/{ns}/example1/{id}"))
336+
assert.NotNil(t, swagger.Paths.Find("/namespaces/{ns}/example1/{did}"))
337+
assert.NotNil(t, swagger.Paths.Value("/namespaces/{ns}/example1/{did}"))
338+
}
311339
func TestFFExcludeTag(t *testing.T) {
312340
routes := []*Route{
313341
{

0 commit comments

Comments
 (0)