From 89f771d4f5ea79b9eda6d2a30f6a866df2ccb1b9 Mon Sep 17 00:00:00 2001 From: weibaohui Date: Tue, 15 Oct 2024 16:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96OpenAPI=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将OpenAPI定义中"additional_properties"的类型从[]interface{}明确为[]map[string]interface{},以更好地表示JSON对象。此更改提高了定义解析的准确性和可读性。 --- internal/kubectl/doc.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/internal/kubectl/doc.go b/internal/kubectl/doc.go index a553ea2..97bae5e 100644 --- a/internal/kubectl/doc.go +++ b/internal/kubectl/doc.go @@ -94,8 +94,11 @@ type RootDefinitions struct { Swagger string `json:"swagger"` Definitions Definitions `json:"definitions,omitempty"` } + +// Definitions 表示所有定义 +// 使用interface{} type Definitions struct { - AdditionalProperties []interface{} `json:"additional_properties"` + AdditionalProperties []map[string]interface{} `json:"additional_properties"` } // definitionsMap 存储所有定义,以便处理引用 @@ -245,24 +248,15 @@ func initDoc() { definitionList := root.Definitions.AdditionalProperties // 进行第一遍处理,此时Ref并没有读取,只是记录了引用 - for _, item := range definitionList { - definition, ok := item.(map[string]interface{}) - jstr := utils.ToJSON(definition) - if !ok { - fmt.Printf("convert definition error\n") - os.Exit(1) - } - + for _, definition := range definitionList { + str := utils.ToJSON(definition) // 解析 Schema 并构建树形结构 - treeRoot, err := parseOpenAPISchema(jstr) + treeRoot, err := parseOpenAPISchema(str) if err != nil { fmt.Printf("Error parsing OpenAPI schema: %v\n", err) os.Exit(1) } trees = append(trees, treeRoot) - // // 打印树形结构 - // printTree(treeRoot, 0) - } // 进行遍历处理,将child中ref对应的类型提取出来