Skip to content

Commit 38c2d1c

Browse files
committed
fix: generated unmarshalJSON in oneOf can not be complied
1 parent f51efe6 commit 38c2d1c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

templates/go/model_oneof.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
6565
dst{{classname}}{{-index}} := &{{classname}}{}
6666
err = json.Unmarshal(data, &dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
6767
if err == nil {
68-
json{{{.}}}, _ := json.Marshal(&dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
68+
json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(&dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
6969
{{#pattern}}
7070
regex := `{{.}}`
7171
regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash
7272
regex = regexp.MustCompile("\\\\(.)").ReplaceAllString(regex, "$1") // Remove duplicate escaping char for dots
7373
rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{dataType}}{{/lambda.type-to-name}}, "$1") // Remove quotes
7474
isMatched, _ := regexp.MatchString(regex, rawString)
7575
{{/pattern}}
76-
if string(json{{{.}}}) != "{}" {{#pattern}}&& isMatched {{/pattern}} { // empty struct
76+
if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) != "{}" {{#pattern}}&& isMatched {{/pattern}} { // empty struct
7777
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}
7878
match++
7979
}

0 commit comments

Comments
 (0)