reset to nil, replace tab wtih space (#6352)

This commit is contained in:
William Cheng 2020-05-19 15:34:53 +08:00 committed by GitHub
parent f8a144bdc1
commit d92b8833b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 136 additions and 119 deletions

View File

@ -40,6 +40,11 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
{{/oneOf}}
if match > 1 { // more than 1 match
// reset to nil
{{#oneOf}}
dst.{{{.}}} = nil
{{/oneOf}}
return fmt.Errorf("Data matches more than one schema in oneOf({{classname}})")
} else if match == 1 {
return nil // exactly one match

View File

@ -62,6 +62,10 @@ func (dst *Fruit) UnmarshalJSON(data []byte) error {
}
if match > 1 { // more than 1 match
// reset to nil
dst.Apple = nil
dst.Banana = nil
return fmt.Errorf("Data matches more than one schema in oneOf(Fruit)")
} else if match == 1 {
return nil // exactly one match

View File

@ -62,6 +62,10 @@ func (dst *FruitReq) UnmarshalJSON(data []byte) error {
}
if match > 1 { // more than 1 match
// reset to nil
dst.AppleReq = nil
dst.BananaReq = nil
return fmt.Errorf("Data matches more than one schema in oneOf(FruitReq)")
} else if match == 1 {
return nil // exactly one match

View File

@ -62,6 +62,10 @@ func (dst *Mammal) UnmarshalJSON(data []byte) error {
}
if match > 1 { // more than 1 match
// reset to nil
dst.Whale = nil
dst.Zebra = nil
return fmt.Errorf("Data matches more than one schema in oneOf(Mammal)")
} else if match == 1 {
return nil // exactly one match