From b8a009ee485f4ad7da1f7c2f81013356a330eaf1 Mon Sep 17 00:00:00 2001 From: thooh Date: Mon, 25 Dec 2023 13:45:00 +0800 Subject: [PATCH] fix(definitions): anonymous --- generate/parser.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/generate/parser.go b/generate/parser.go index 147ee18..aa09f37 100644 --- a/generate/parser.go +++ b/generate/parser.go @@ -482,6 +482,7 @@ func renderReplyAsDefinition(d swaggerDefinitionsObject, m messageMap, p []spec. schema.Title = defineStruct.Name() + km := make(map[string]int) for _, member := range defineStruct.Members { if hasPathParameters(member) { continue @@ -510,6 +511,12 @@ func renderReplyAsDefinition(d swaggerDefinitionsObject, m messageMap, p []spec. if schema.Properties == nil { schema.Properties = &swaggerSchemaObjectProperties{} } + + if _, ok := km[mkv.Key]; ok { + continue + } + km[mkv.Key] = len(*schema.Properties) + *schema.Properties = append(*schema.Properties, mkv) } continue @@ -517,6 +524,11 @@ func renderReplyAsDefinition(d swaggerDefinitionsObject, m messageMap, p []spec. if schema.Properties == nil { schema.Properties = &swaggerSchemaObjectProperties{} } + + if idx, ok := km[kv.Key]; ok { + *schema.Properties = append((*schema.Properties)[:idx], (*schema.Properties)[idx+1:]...) + } + km[kv.Key] = len(*schema.Properties) *schema.Properties = append(*schema.Properties, kv) for _, tag := range member.Tags() { @@ -572,7 +584,7 @@ func schemaOfField(member spec.Member) swaggerSchemaObject { comment = strings.Replace(comment, "//", "", -1) switch ft := kind; ft { - case reflect.Invalid: //[]Struct 也有可能是 Struct + case reflect.Invalid: // []Struct 也有可能是 Struct // []Struct // map[ArrayType:map[Star:map[StringExpr:UserSearchReq] StringExpr:*UserSearchReq] StringExpr:[]*UserSearchReq] refTypeName := strings.Replace(member.Type.Name(), "[", "", 1)