diff --git a/blacklist.txt b/blacklist.txt index 5b7d215..d48458c 100644 --- a/blacklist.txt +++ b/blacklist.txt @@ -4,5 +4,4 @@ featuretoggle workflows openstack notebooks -observability cost diff --git a/templates/go/custom/helper/array_json_example_value.mustache b/templates/go/custom/helper/array_json_example_value.mustache new file mode 100644 index 0000000..00b75f8 --- /dev/null +++ b/templates/go/custom/helper/array_json_example_value.mustache @@ -0,0 +1 @@ +{{#isArray}}[{{#items}}{{#isString}}"example"{{/isString}}{{/items}}]{{/isArray}} \ No newline at end of file diff --git a/templates/go/custom/helper/container_json_example_value.mustache b/templates/go/custom/helper/container_json_example_value.mustache new file mode 100644 index 0000000..4643fa7 --- /dev/null +++ b/templates/go/custom/helper/container_json_example_value.mustache @@ -0,0 +1 @@ +{{#isContainer}}{{#isMap}}{"map":{{#items}}{{> custom/helper/array_json_example_value}}{{^isArray}}{{#isString}}"example"{{/isString}}{{/isArray}}{{/items}}}{{/isMap}}{{^isMap}}{{> custom/helper/array_json_example_value}}{{/isMap}}{{/isContainer}} \ No newline at end of file diff --git a/templates/go/custom/model_oneof_test.mustache b/templates/go/custom/model_oneof_test.mustache index 068d98e..cb2b712 100644 --- a/templates/go/custom/model_oneof_test.mustache +++ b/templates/go/custom/model_oneof_test.mustache @@ -27,15 +27,23 @@ func Test{{{classname}}}_UnmarshalJSON(t *testing.T) { wantErr: false, }, {{/allowableValues.values}} - {{^allowableValues.values}}{{^isModel}} + {{^allowableValues.values}}{{^isModel}}{{^isContainer}} { - name: "success - {{dataType}} {{example}}", + name: "success - {{dataType}} {{{example}}}", args: args{ - src: []byte(`"{{example}}"`), + src: []byte(`"{{{example}}}"`), }, wantErr: false, }, - {{/isModel}}{{/allowableValues.values}} + {{/isContainer}}{{#isContainer}} + { + name: "success - {{dataType}}", + args: args{ + src: []byte(`{{>custom/helper/container_json_example_value}}`), + }, + wantErr: false, + }, + {{/isContainer}}{{/isModel}}{{/allowableValues.values}} {{#-last}} } for _, tt := range tests { diff --git a/templates/go/model_oneof.mustache b/templates/go/model_oneof.mustache index a3474f9..f179d14 100644 --- a/templates/go/model_oneof.mustache +++ b/templates/go/model_oneof.mustache @@ -65,7 +65,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { dst{{classname}}{{-index}} := &{{classname}}{} err = json.Unmarshal(data, &dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) if err == nil { - json{{{.}}}, _ := json.Marshal(&dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) + json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(&dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) {{#pattern}} regex := `{{.}}` regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash @@ -73,7 +73,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{dataType}}{{/lambda.type-to-name}}, "$1") // Remove quotes isMatched, _ := regexp.MatchString(regex, rawString) {{/pattern}} - if string(json{{{.}}}) != "{}" {{#pattern}}&& isMatched {{/pattern}} { // empty struct + if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) != "{}" {{#pattern}}&& isMatched {{/pattern}} { // empty struct dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} match++ }