diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache index 204970de29d3e6a271ad1cd46782f5f8ba2a7b03..86cda3bc747b080b7552d7e6ba0f6586cb5d08d5 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_anyof.mustache @@ -43,3 +43,5 @@ func (src *{{classname}}) MarshalJSON() ([]byte, error) { {{/anyOf}} return nil, nil // no data in anyOf schemas } + +{{>nullable_model}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache index 53ee65aac2d8a9640d0c2a374e8084f510cf472b..c0c498db14e02ae3414a58ca8220bfaa2797ea55 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_oneof.mustache @@ -75,3 +75,5 @@ func (obj *{{classname}}) GetActualInstance() (interface{}) { // all schemas are nil return nil } + +{{>nullable_model}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache index 0a06b4a2743226531c427934f1d96d0b1b63b2fe..1078787c86dde51aa8d790c3e51ddd1ade9e1d53 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model_simple.mustache @@ -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}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/go-experimental/nullable_model.mustache b/modules/openapi-generator/src/main/resources/go-experimental/nullable_model.mustache new file mode 100644 index 0000000000000000000000000000000000000000..20d357691305cd7469b4c6cb42bcbac4d9bba91c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/go-experimental/nullable_model.mustache @@ -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) +} diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go index 5863b9c588b8701be02da5db242579621178f7d4..b50054da7ff1e87936fd238bf3f078f02443743a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit.go @@ -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) +} + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go index c1ee08e0881a8feef5ca91cc5e29f4578d2677f4..41e7c2a5a1808930374ef6d454e3ce5a9a7b5f6e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go @@ -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) +} + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go index 997688ee1439e82bc995ae150ffc36cf9e9380bb..03baf438d135fd694737ffaedc31f4de47e73e50 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_gm_fruit.go @@ -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) +} + diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go index b540a411a4fbdd88cf4abdaaa1e50e00e0fd7573..77e8ee3e97c14aa03bc0ff71665110a576effa0c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mammal.go @@ -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) +} +