forked from loafle/openapi-generator-original
[go-experimental] Fix marshalling of of go oneOf structures to work on non-pointer receivers (#6314)
This commit is contained in:
@@ -13,7 +13,7 @@ func {{{.}}}As{{classname}}(v *{{{.}}}) {{classname}} {
|
||||
|
||||
{{/oneOf}}
|
||||
|
||||
// Unmarshl JSON data into one of the pointers in the struct
|
||||
// Unmarshal JSON data into one of the pointers in the struct
|
||||
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
match := 0
|
||||
@@ -53,8 +53,8 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Marshl data from the first non-nil pointers in the struct to JSON
|
||||
func (src *{{classname}}) MarshalJSON() ([]byte, error) {
|
||||
// Marshal data from the first non-nil pointers in the struct to JSON
|
||||
func (src {{classname}}) MarshalJSON() ([]byte, error) {
|
||||
{{#oneOf}}
|
||||
if src.{{{.}}} != nil {
|
||||
return json.Marshal(&src.{{{.}}})
|
||||
|
||||
@@ -31,7 +31,7 @@ func BananaAsFruit(v *Banana) Fruit {
|
||||
}
|
||||
|
||||
|
||||
// Unmarshl JSON data into one of the pointers in the struct
|
||||
// Unmarshal JSON data into one of the pointers in the struct
|
||||
func (dst *Fruit) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
match := 0
|
||||
@@ -74,8 +74,8 @@ func (dst *Fruit) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Marshl data from the first non-nil pointers in the struct to JSON
|
||||
func (src *Fruit) MarshalJSON() ([]byte, error) {
|
||||
// Marshal data from the first non-nil pointers in the struct to JSON
|
||||
func (src Fruit) MarshalJSON() ([]byte, error) {
|
||||
if src.Apple != nil {
|
||||
return json.Marshal(&src.Apple)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func BananaReqAsFruitReq(v *BananaReq) FruitReq {
|
||||
}
|
||||
|
||||
|
||||
// Unmarshl JSON data into one of the pointers in the struct
|
||||
// Unmarshal JSON data into one of the pointers in the struct
|
||||
func (dst *FruitReq) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
match := 0
|
||||
@@ -74,8 +74,8 @@ func (dst *FruitReq) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Marshl data from the first non-nil pointers in the struct to JSON
|
||||
func (src *FruitReq) MarshalJSON() ([]byte, error) {
|
||||
// Marshal data from the first non-nil pointers in the struct to JSON
|
||||
func (src FruitReq) MarshalJSON() ([]byte, error) {
|
||||
if src.AppleReq != nil {
|
||||
return json.Marshal(&src.AppleReq)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func ZebraAsMammal(v *Zebra) Mammal {
|
||||
}
|
||||
|
||||
|
||||
// Unmarshl JSON data into one of the pointers in the struct
|
||||
// Unmarshal JSON data into one of the pointers in the struct
|
||||
func (dst *Mammal) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
match := 0
|
||||
@@ -74,8 +74,8 @@ func (dst *Mammal) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Marshl data from the first non-nil pointers in the struct to JSON
|
||||
func (src *Mammal) MarshalJSON() ([]byte, error) {
|
||||
// Marshal data from the first non-nil pointers in the struct to JSON
|
||||
func (src Mammal) MarshalJSON() ([]byte, error) {
|
||||
if src.Whale != nil {
|
||||
return json.Marshal(&src.Whale)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user