mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
[go-experimental] Ensure that all oneOf/anyOf models have their Nullable<Model> defined (#6363)
This commit is contained in:
parent
755336f9d9
commit
5f2979c434
@ -43,3 +43,5 @@ func (src *{{classname}}) MarshalJSON() ([]byte, error) {
|
||||
{{/anyOf}}
|
||||
return nil, nil // no data in anyOf schemas
|
||||
}
|
||||
|
||||
{{>nullable_model}}
|
@ -75,3 +75,5 @@ func (obj *{{classname}}) GetActualInstance() (interface{}) {
|
||||
// all schemas are nil
|
||||
return nil
|
||||
}
|
||||
|
||||
{{>nullable_model}}
|
@ -249,38 +249,4 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(toSerialize)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
{{>nullable_model}}
|
35
modules/openapi-generator/src/main/resources/go-experimental/nullable_model.mustache
vendored
Normal file
35
modules/openapi-generator/src/main/resources/go-experimental/nullable_model.mustache
vendored
Normal 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)
|
||||
}
|
@ -101,3 +101,39 @@ func (obj *Fruit) GetActualInstance() (interface{}) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -101,3 +101,39 @@ func (obj *FruitReq) GetActualInstance() (interface{}) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -65,3 +65,39 @@ func (src *GmFruit) MarshalJSON() ([]byte, error) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -101,3 +101,39 @@ func (obj *Mammal) GetActualInstance() (interface{}) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user