Skip to content

Commit 0aad2df

Browse files
committed
feat: implement GetOpenAPICompatiblePathPattern method in Framework interface and update endpoint registration for OpenAPI compatibility
1 parent 92ab2c9 commit 0aad2df

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *App) Sync() {
6565
for _, e := range s.endpoints {
6666
s.framework.Register(e.path, e.method, s.createHandler(e.handlers...))
6767
if e.addToSpec {
68-
s.spec.Register(e.path, e.method, e.handlers...)
68+
s.spec.Register(s.framework.GetOpenAPICompatiblePathPattern(e.path), e.method, e.handlers...)
6969
}
7070
}
7171
}

pkg/framework/fiberframework/framework.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fiberframework
33
import (
44
"net/http"
55
"net/http/httptest"
6+
"strings"
67

78
"github.com/go-simpl/simplapi/pkg/context"
89
"github.com/go-simpl/simplapi/pkg/framework"
@@ -25,6 +26,16 @@ func (f *fiberFramework) GetNativeApp() interface{} {
2526
return f.app
2627
}
2728

29+
func (f *fiberFramework) GetOpenAPICompatiblePathPattern(path string) string {
30+
pathParts := strings.Split(path, "/")
31+
for i, part := range pathParts {
32+
if strings.HasPrefix(part, ":") {
33+
pathParts[i] = "{" + part[1:] + "}"
34+
}
35+
}
36+
return strings.Join(pathParts, "/")
37+
}
38+
2839
func (f *fiberFramework) Register(path string, method string, handler framework.FrameworkHandler) {
2940
switch method {
3041
case http.MethodGet:

pkg/framework/ginframework/framework.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func (g *ginFramework) GetNativeApp() interface{} {
2727
return g.engine
2828
}
2929

30+
func (g *ginFramework) GetOpenAPICompatiblePathPattern(path string) string {
31+
return path
32+
}
33+
3034
func (g *ginFramework) Register(path string, method string, handler framework.FrameworkHandler) {
3135
switch method {
3236
case http.MethodGet:

pkg/framework/iface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Framework interface {
1414
Shutdown() error
1515

1616
GetNativeApp() interface{}
17+
GetOpenAPICompatiblePathPattern(path string) string
1718

1819
TestRequest(req *http.Request) (*http.Response, error)
1920
}

0 commit comments

Comments
 (0)