Skip to content

Commit

Permalink
removed datly code generation coupling with hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Nov 27, 2023
1 parent 70ce6bc commit 70427e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
9 changes: 4 additions & 5 deletions stringify.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ func stringify(expr ast.Node, builder *strings.Builder) error {
case *ast.StructType:
builder.WriteString("struct{")
for _, field := range actual.Fields.List {
builder.WriteString(field.Names[0].Name)
if len(field.Names) > 0 {
builder.WriteString(field.Names[0].Name)
}
builder.WriteString(" ")

stringify(field.Type, builder)
}
builder.WriteString("}")
Expand Down Expand Up @@ -188,9 +189,7 @@ func (t *Type) stringify(rType reflect.Type, tag reflect.StructTag, builder *str
t.stringify(aField.Type, aField.Tag, builder)
}
if aField.Tag != "" {
builder.WriteString(" `")
builder.WriteString(fieldTag)
builder.WriteString("`")
builder.WriteString(" `" + fieldTag + "`")
}
builder.WriteString("; ")
}
Expand Down
13 changes: 6 additions & 7 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,13 @@ func buildGoType(mainBuilder *strings.Builder, importsBuilder *strings.Builder,
nestedStruct := &strings.Builder{}
structBuilders = append(structBuilders, nestedStruct)
if !strings.Contains(typeName, ".") && !skipTypeGeneration {
if opts.generateOption.buildTypes[typeName] {
continue
if !opts.generateOption.buildTypes[typeName] {
opts.generateOption.buildTypes[typeName] = true
nestedStruct.WriteString("type ")
nestedStruct.WriteString(typeName)
nestedStruct.WriteByte(' ')
structBuilders = append(structBuilders, buildGoType(nestedStruct, importsBuilder, actualType, imports, false, opts)...)
}
opts.generateOption.buildTypes[typeName] = true
nestedStruct.WriteString("type ")
nestedStruct.WriteString(typeName)
nestedStruct.WriteByte(' ')
structBuilders = append(structBuilders, buildGoType(nestedStruct, importsBuilder, actualType, imports, false, opts)...)
}
}
} else {
Expand Down

0 comments on commit 70427e4

Please sign in to comment.