Skip to content

Commit

Permalink
Feature: Also add json tag with just the name
Browse files Browse the repository at this point in the history
  • Loading branch information
vraut-pdgc committed Dec 6, 2021
1 parent 5b138fb commit 9e53177
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gentests/_testgen/testgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func genXSDTests(cfg xsdgen.Config, data []byte, pkg string) (code, tests *ast.F
fields = append(fields,
gen.Public(elem.Name.Local),
ast.NewIdent(main.NameOf(elem.Type)),
gen.String(fmt.Sprintf(`xml:"%s %s"`, elem.Name.Space, elem.Name.Local)))
gen.String(fmt.Sprintf(`json:"%s" xml:"%s %s"`, elem.Name.Local, elem.Name.Space, elem.Name.Local)))
}
expr, err := gen.ToString(gen.Struct(fields...))
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion xsdgen/xsdgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func (cfg *Config) genComplexType(t *xsd.ComplexType) ([]spec, error) {
if el.Nillable || el.Optional {
options = ",omitempty"
}
tag := fmt.Sprintf(`xml:"%s %s%s"`, el.Name.Space, el.Name.Local, options)
tag := fmt.Sprintf(`json:"%s%s" xml:"%s %s%s"`, el.Name.Local, options, el.Name.Space, el.Name.Local, options)
base, err := cfg.expr(el.Type)
if err != nil {
return nil, fmt.Errorf("%s element %s: %v", t.Name.Local, el.Name.Local, err)
Expand Down Expand Up @@ -743,6 +743,7 @@ func (cfg *Config) genComplexType(t *xsd.ComplexType) ([]spec, error) {
} else {
tag = fmt.Sprintf(`xml:"%s,attr%s"`, attr.Name.Local, options)
}
tag = fmt.Sprintf(`json:"%s%s" %s`, attr.Name.Local, options, tag)
base, err := cfg.expr(attr.Type)
if err != nil {
return nil, fmt.Errorf("%s attribute %s: %v", t.Name.Local, attr.Name.Local, err)
Expand Down

0 comments on commit 9e53177

Please sign in to comment.