Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对匿名属性的生成请求体问题处理 #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion generate/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -510,13 +511,24 @@ 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
}
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() {
Expand Down Expand Up @@ -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)
Expand Down