diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index f74fc88a84c5..0bff8913d4a5 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -137,6 +137,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/modules/openapi-generator/src/main/resources/go/model_oneof.mustache b/modules/openapi-generator/src/main/resources/go/model_oneof.mustache index e62c5e82d2b1..77b6e99e072c 100644 --- a/modules/openapi-generator/src/main/resources/go/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/go/model_oneof.mustache @@ -145,4 +145,16 @@ func (obj *{{classname}}) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj {{classname}}) GetActualInstanceValue() (interface{}) { +{{#oneOf}} + if obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil { + return *obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} + } + +{{/oneOf}} + // all schemas are nil + return nil +} + {{>nullable_model}} diff --git a/samples/client/echo_api/go-external-refs/client.go b/samples/client/echo_api/go-external-refs/client.go index 29662b18543d..0acd53304c6a 100644 --- a/samples/client/echo_api/go-external-refs/client.go +++ b/samples/client/echo_api/go-external-refs/client.go @@ -143,6 +143,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/client/echo_api/go/client.go b/samples/client/echo_api/go/client.go index 29662b18543d..0acd53304c6a 100644 --- a/samples/client/echo_api/go/client.go +++ b/samples/client/echo_api/go/client.go @@ -143,6 +143,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go b/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go index c1d35e12a5ab..6fce88a8015a 100644 --- a/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go +++ b/samples/client/others/go/allof_multiple_ref_and_discriminator/client.go @@ -124,6 +124,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/client/others/go/oneof-anyof-required/client.go b/samples/client/others/go/oneof-anyof-required/client.go index c1d35e12a5ab..6fce88a8015a 100644 --- a/samples/client/others/go/oneof-anyof-required/client.go +++ b/samples/client/others/go/oneof-anyof-required/client.go @@ -124,6 +124,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/client/others/go/oneof-anyof-required/model_object.go b/samples/client/others/go/oneof-anyof-required/model_object.go index b7ffee7b20cc..86093dd1f9a6 100644 --- a/samples/client/others/go/oneof-anyof-required/model_object.go +++ b/samples/client/others/go/oneof-anyof-required/model_object.go @@ -118,6 +118,20 @@ func (obj *Object) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj Object) GetActualInstanceValue() (interface{}) { + if obj.NestedObject1 != nil { + return *obj.NestedObject1 + } + + if obj.NestedObject2 != nil { + return *obj.NestedObject2 + } + + // all schemas are nil + return nil +} + type NullableObject struct { value *Object isSet bool diff --git a/samples/client/others/go/oneof-discriminator-lookup/client.go b/samples/client/others/go/oneof-discriminator-lookup/client.go index c1d35e12a5ab..6fce88a8015a 100644 --- a/samples/client/others/go/oneof-discriminator-lookup/client.go +++ b/samples/client/others/go/oneof-discriminator-lookup/client.go @@ -124,6 +124,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/client/others/go/oneof-discriminator-lookup/model_object.go b/samples/client/others/go/oneof-discriminator-lookup/model_object.go index f3c77efa679c..9b59ff805e88 100644 --- a/samples/client/others/go/oneof-discriminator-lookup/model_object.go +++ b/samples/client/others/go/oneof-discriminator-lookup/model_object.go @@ -127,6 +127,20 @@ func (obj *Object) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj Object) GetActualInstanceValue() (interface{}) { + if obj.NestedObject1 != nil { + return *obj.NestedObject1 + } + + if obj.NestedObject2 != nil { + return *obj.NestedObject2 + } + + // all schemas are nil + return nil +} + type NullableObject struct { value *Object isSet bool diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index af5ee9f2f29c..c47d065a79aa 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -143,6 +143,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go index 6a36cf12e03f..ef706c87728c 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go +++ b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/client.go @@ -127,6 +127,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go index 8f8601625f13..9560cb90583f 100644 --- a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go +++ b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go @@ -128,6 +128,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index 78fd61f75fc4..3f017c316e8e 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -146,6 +146,10 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { func parameterValueToString( obj interface{}, key string ) string { if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + return fmt.Sprintf("%v", obj) } var param,ok = obj.(MappedNullable) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go b/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go index c41f34c77720..729263da4a6b 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go @@ -118,6 +118,20 @@ func (obj *Fruit) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj Fruit) GetActualInstanceValue() (interface{}) { + if obj.Apple != nil { + return *obj.Apple + } + + if obj.Banana != nil { + return *obj.Banana + } + + // all schemas are nil + return nil +} + type NullableFruit struct { value *Fruit isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go index efacc61f2d04..df062413d6c3 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_fruit_req.go @@ -118,6 +118,20 @@ func (obj *FruitReq) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj FruitReq) GetActualInstanceValue() (interface{}) { + if obj.AppleReq != nil { + return *obj.AppleReq + } + + if obj.BananaReq != nil { + return *obj.BananaReq + } + + // all schemas are nil + return nil +} + type NullableFruitReq struct { value *FruitReq isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go b/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go index 489f80066443..c151ad3b780f 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_incident_data.go @@ -123,6 +123,20 @@ func (obj *IncidentData) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj IncidentData) GetActualInstanceValue() (interface{}) { + if obj.ArrayOfMapmapOfStringAny != nil { + return *obj.ArrayOfMapmapOfStringAny + } + + if obj.MapmapOfStringAny != nil { + return *obj.MapmapOfStringAny + } + + // all schemas are nil + return nil +} + type NullableIncidentData struct { value *IncidentData isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go b/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go index 964028042326..6b0cbe76babf 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go @@ -118,6 +118,20 @@ func (obj *Mammal) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj Mammal) GetActualInstanceValue() (interface{}) { + if obj.Whale != nil { + return *obj.Whale + } + + if obj.Zebra != nil { + return *obj.Zebra + } + + // all schemas are nil + return nil +} + type NullableMammal struct { value *Mammal isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go index db39bd3ec403..f8ddcb844b53 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type.go @@ -152,6 +152,24 @@ func (obj *OneOfPrimitiveType) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj OneOfPrimitiveType) GetActualInstanceValue() (interface{}) { + if obj.OneOfPrimitiveTypeChild != nil { + return *obj.OneOfPrimitiveTypeChild + } + + if obj.ArrayOfString != nil { + return *obj.ArrayOfString + } + + if obj.Int32 != nil { + return *obj.Int32 + } + + // all schemas are nil + return nil +} + type NullableOneOfPrimitiveType struct { value *OneOfPrimitiveType isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go index 246214e8fc23..e0a663e89b59 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_types.go @@ -119,6 +119,20 @@ func (obj *OneOfPrimitiveTypes) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj OneOfPrimitiveTypes) GetActualInstanceValue() (interface{}) { + if obj.String != nil { + return *obj.String + } + + if obj.TimeTime != nil { + return *obj.TimeTime + } + + // all schemas are nil + return nil +} + type NullableOneOfPrimitiveTypes struct { value *OneOfPrimitiveTypes isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go index 06563e658a95..9f1e73398b11 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_with_complex_type.go @@ -118,6 +118,20 @@ func (obj *OneOfWithComplexType) GetActualInstance() (interface{}) { return nil } +// Get the actual instance value +func (obj OneOfWithComplexType) GetActualInstanceValue() (interface{}) { + if obj.ArrayOfString != nil { + return *obj.ArrayOfString + } + + if obj.String != nil { + return *obj.String + } + + // all schemas are nil + return nil +} + type NullableOneOfWithComplexType struct { value *OneOfWithComplexType isSet bool