Skip to content

Commit

Permalink
Merge pull request #494 from okta/ssaxena/fix-code-gen
Browse files Browse the repository at this point in the history
Fix codegen process to avoid manual intervention
  • Loading branch information
sachinsaxena-okta authored Nov 22, 2024
2 parents 370527b + f443c03 commit 964f066
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .generator/templates/model_oneof.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//model_oneof.mustache
// {{classname}} - {{{description}}}{{^description}}struct for {{{classname}}}{{/description}}
type {{classname}} struct {
Expand Down Expand Up @@ -59,8 +60,8 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
// try to unmarshal data into {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}
err = json.Unmarshal(data, &dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
if err == nil {
json{{{.}}}, _ := json.Marshal(dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
if string(json{{{.}}}) == "{}" { // empty struct
json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) == "{}" { // empty struct
dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil
} else {
match++
Expand Down Expand Up @@ -142,4 +143,4 @@ func (obj *{{classname}}) GetActualInstance() (interface{}) {
return nil
}

{{>nullable_model}}
{{>nullable_model}}

0 comments on commit 964f066

Please sign in to comment.