[go-experimental] Ensure that all oneOf/anyOf models have their Nullable<Model> defined (#6363)

This commit is contained in:
Slavek Kabrda 2020-05-20 11:29:03 +02:00 committed by GitHub
parent 755336f9d9
commit 5f2979c434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 184 additions and 35 deletions

View File

@ -43,3 +43,5 @@ func (src *{{classname}}) MarshalJSON() ([]byte, error) {
{{/anyOf}} {{/anyOf}}
return nil, nil // no data in anyOf schemas return nil, nil // no data in anyOf schemas
} }
{{>nullable_model}}

View File

@ -75,3 +75,5 @@ func (obj *{{classname}}) GetActualInstance() (interface{}) {
// all schemas are nil // all schemas are nil
return nil return nil
} }
{{>nullable_model}}

View File

@ -249,38 +249,4 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) {
return json.Marshal(toSerialize) return json.Marshal(toSerialize)
} }
type Nullable{{{classname}}} struct { {{>nullable_model}}
value *{{{classname}}}
isSet bool
}
func (v Nullable{{classname}}) Get() *{{classname}} {
return v.value
}
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
v.value = val
v.isSet = true
}
func (v Nullable{{classname}}) IsSet() bool {
return v.isSet
}
func (v *Nullable{{classname}}) Unset() {
v.value = nil
v.isSet = false
}
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
return &Nullable{{classname}}{value: val, isSet: true}
}
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,35 @@
type Nullable{{{classname}}} struct {
value *{{{classname}}}
isSet bool
}
func (v Nullable{{classname}}) Get() *{{classname}} {
return v.value
}
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
v.value = val
v.isSet = true
}
func (v Nullable{{classname}}) IsSet() bool {
return v.isSet
}
func (v *Nullable{{classname}}) Unset() {
v.value = nil
v.isSet = false
}
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
return &Nullable{{classname}}{value: val, isSet: true}
}
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -101,3 +101,39 @@ func (obj *Fruit) GetActualInstance() (interface{}) {
return nil return nil
} }
type NullableFruit struct {
value *Fruit
isSet bool
}
func (v NullableFruit) Get() *Fruit {
return v.value
}
func (v *NullableFruit) Set(val *Fruit) {
v.value = val
v.isSet = true
}
func (v NullableFruit) IsSet() bool {
return v.isSet
}
func (v *NullableFruit) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableFruit(val *Fruit) *NullableFruit {
return &NullableFruit{value: val, isSet: true}
}
func (v NullableFruit) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableFruit) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -101,3 +101,39 @@ func (obj *FruitReq) GetActualInstance() (interface{}) {
return nil return nil
} }
type NullableFruitReq struct {
value *FruitReq
isSet bool
}
func (v NullableFruitReq) Get() *FruitReq {
return v.value
}
func (v *NullableFruitReq) Set(val *FruitReq) {
v.value = val
v.isSet = true
}
func (v NullableFruitReq) IsSet() bool {
return v.isSet
}
func (v *NullableFruitReq) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableFruitReq(val *FruitReq) *NullableFruitReq {
return &NullableFruitReq{value: val, isSet: true}
}
func (v NullableFruitReq) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableFruitReq) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -65,3 +65,39 @@ func (src *GmFruit) MarshalJSON() ([]byte, error) {
return nil, nil // no data in anyOf schemas return nil, nil // no data in anyOf schemas
} }
type NullableGmFruit struct {
value *GmFruit
isSet bool
}
func (v NullableGmFruit) Get() *GmFruit {
return v.value
}
func (v *NullableGmFruit) Set(val *GmFruit) {
v.value = val
v.isSet = true
}
func (v NullableGmFruit) IsSet() bool {
return v.isSet
}
func (v *NullableGmFruit) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableGmFruit(val *GmFruit) *NullableGmFruit {
return &NullableGmFruit{value: val, isSet: true}
}
func (v NullableGmFruit) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableGmFruit) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -101,3 +101,39 @@ func (obj *Mammal) GetActualInstance() (interface{}) {
return nil return nil
} }
type NullableMammal struct {
value *Mammal
isSet bool
}
func (v NullableMammal) Get() *Mammal {
return v.value
}
func (v *NullableMammal) Set(val *Mammal) {
v.value = val
v.isSet = true
}
func (v NullableMammal) IsSet() bool {
return v.isSet
}
func (v *NullableMammal) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableMammal(val *Mammal) *NullableMammal {
return &NullableMammal{value: val, isSet: true}
}
func (v NullableMammal) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableMammal) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}