From aec7ff61fd48df4c7af1f0e3d4e0658c674b7d5c Mon Sep 17 00:00:00 2001 From: Zodial Date: Thu, 14 Dec 2023 16:28:39 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E7=94=9F=E6=88=90ts=E7=9A=84?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E6=9C=89=E5=BA=8F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/ts.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/console/commands/ts.go b/console/commands/ts.go index 1b0ca59..7a08c3d 100644 --- a/console/commands/ts.go +++ b/console/commands/ts.go @@ -10,6 +10,8 @@ import ( "net/http" "os" "regexp" + "sort" + "strconv" "strings" ) @@ -284,12 +286,19 @@ func (t *Ts) getTsTypeFromSchema(schema *openapi.Schema, ref string) string { func (t *Ts) genEnums(enumName string, schema *openapi.Schema) { str := fmt.Sprintf("export enum %s {\n", enumName) - for k, item := range schema.Properties { - desc := t.clearEmpty(strings.TrimLeft(item.Description, "enum|")) + var keys []int + for k, _ := range schema.Properties { + i, _ := strconv.Atoi(k) + keys = append(keys, i) + } + sort.Ints(keys) + for _, i := range keys { + k := strconv.Itoa(i) + desc := t.clearEmpty(strings.TrimLeft(schema.Properties[k].Description, "enum|")) if desc != "" { str += fmt.Sprintf(" // %s\n", desc) } - str += fmt.Sprintf(" %s = %s,\n", item.Type, k) + str += fmt.Sprintf(" %s = %s,\n", schema.Properties[k].Type, k) } str += "}\n" t.enums[enumName] = str