Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

修复:同步 knowledge-search 的 Swagger 路由

T3L0004e53aa9d7771
diff --git a/docs/docs.go b/docs/docs.go
index f69ff5723..766c5fa6e 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -10836,7 +10836,7 @@ const docTemplate = `{
}
}
},
- "/sessions/search": {
+ "/knowledge-search": {
"post": {
"security": [
{
diff --git a/docs/swagger.json b/docs/swagger.json
index 5c09304e1..02cad3306 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -10829,7 +10829,7 @@
}
}
},
- "/sessions/search": {
+ "/knowledge-search": {
"post": {
"security": [
{
@@ -22705,4 +22705,4 @@
"in": "header"
}
}
-}
\ No newline at end of file
+}
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index e67f0cf1f..6e1d36507 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -13112,7 +13112,7 @@ paths:
summary: 继续流式响应
tags:
- 问答
- /sessions/search:
+ /knowledge-search:
post:
consumes:
- application/json
diff --git a/docs/swagger_contract_test.go b/docs/swagger_contract_test.go
new file mode 100644
index 000000000..e701ee62e
--- /dev/null
+++ b/docs/swagger_contract_test.go
@@ -0,0 +1,82 @@
+package docs_test
+
+import (
+ "encoding/json"
+ "os"
+ "testing"
+
+ docs "github.com/Tencent/WeKnora/docs"
+ "gopkg.in/yaml.v3"
+)
+
+func TestKnowledgeSearchRouteContract(t *testing.T) {
+ tests := []struct {
+ name string
+ loadSpec func(t *testing.T) []byte
+ parse func([]byte, any) error
+ }{
+ {
+ name: "registered document",
+ loadSpec: func(t *testing.T) []byte {
+ t.Helper()
+ return []byte(docs.SwaggerInfo.ReadDoc())
+ },
+ parse: json.Unmarshal,
+ },
+ {
+ name: "swagger.json",
+ loadSpec: func(t *testing.T) []byte {
+ t.Helper()
+ return readSwaggerFile(t, "swagger.json")
+ },
+ parse: json.Unmarshal,
+ },
+ {
+ name: "swagger.yaml",
+ loadSpec: func(t *testing.T) []byte {
+ t.Helper()
+ return readSwaggerFile(t, "swagger.yaml")
+ },
+ parse: yaml.Unmarshal,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assertKnowledgeSearchRouteContract(t, tt.loadSpec(t), tt.parse)
+ })
+ }
+}
+
+func readSwaggerFile(t *testing.T, name string) []byte {
+ t.Helper()
+ data, err := os.ReadFile(name)
+ if err != nil {
+ t.Fatalf("read %s: %v", name, err)
+ }
+ return data
+}
+
+func assertKnowledgeSearchRouteContract(t *testing.T, data []byte, parse func([]byte, any) error) {
+ t.Helper()
+ var spec struct {
+ Paths map[string]map[string]any `json:"paths" yaml:"paths"`
+ }
+ if err := parse(data, &spec); err != nil {
+ t.Fatalf("parse generated Swagger document: %v", err)
+ }
+
+ knowledgeSearch, ok := spec.Paths["/knowledge-search"]
+ if !ok {
+ t.Fatal("generated Swagger document does not expose /knowledge-search")
+ }
+ if _, ok := knowledgeSearch["post"]; !ok {
+ t.Fatal("generated Swagger document does not expose POST /knowledge-search")
+ }
+
+ if staleRoute, ok := spec.Paths["/sessions/search"]; ok {
+ if _, ok := staleRoute["post"]; ok {
+ t.Fatal("generated Swagger document still exposes stale POST /sessions/search")
+ }
+ }
+}
diff --git a/internal/handler/session/qa.go b/internal/handler/session/qa.go
index a700cae7d..afe5e0e91 100644
--- a/internal/handler/session/qa.go
+++ b/internal/handler/session/qa.go
@@ -697,7 +697,7 @@ func (h *Handler) setupSSEStream(reqCtx *qaRequestContext, generateTitle bool) *
// @Failure 400 {object} errors.AppError "请求参数错误"
// @Security Bearer
// @Security ApiKeyAuth
-// @Router /sessions/search [post]
+// @Router /knowledge-search [post]
func (h *Handler) SearchKnowledge(c *gin.Context) {
ctx := logger.CloneContext(c.Request.Context())
logger.Info(ctx, "Start processing knowledge search request")