From d5f42500abe1340fa6ed06d77ab4b9f922fc6fad Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 24 Jun 2024 11:58:57 +0800 Subject: [PATCH] [Golang] Move utility functions from client.mustache to utils.mustache (#19001) * [Golang] Move utility functions from client.mustache to utils.mustache * re-generate Go samples * re-generate Go samples again * re-generate samples once more * update go samples --------- Co-authored-by: Martin Lakov --- .../src/main/resources/go/client.mustache | 12 ------------ .../src/main/resources/go/utils.mustache | 14 ++++++++++++++ samples/client/echo_api/go-external-refs/client.go | 12 ------------ samples/client/echo_api/go-external-refs/utils.go | 14 ++++++++++++++ samples/client/echo_api/go/client.go | 12 ------------ samples/client/echo_api/go/utils.go | 14 ++++++++++++++ .../allof_multiple_ref_and_discriminator/client.go | 12 ------------ .../allof_multiple_ref_and_discriminator/utils.go | 14 ++++++++++++++ .../others/go/oneof-anyof-required/client.go | 12 ------------ .../client/others/go/oneof-anyof-required/utils.go | 14 ++++++++++++++ samples/client/petstore/go/go-petstore/client.go | 12 ------------ samples/client/petstore/go/go-petstore/utils.go | 14 ++++++++++++++ .../x-auth-id-alias/go-experimental/client.go | 12 ------------ .../x-auth-id-alias/go-experimental/utils.go | 14 ++++++++++++++ .../client.go | 12 ------------ .../go-petstore-generateMarshalJSON-false/utils.go | 14 ++++++++++++++ .../client/petstore/go/go-petstore/client.go | 12 ------------ .../client/petstore/go/go-petstore/utils.go | 14 ++++++++++++++ samples/server/petstore/go-gin-api-server/go.sum | 5 +++++ 19 files changed, 131 insertions(+), 108 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 2b43d4d1b317..a5f058b8e849 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -585,18 +585,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/modules/openapi-generator/src/main/resources/go/utils.mustache b/modules/openapi-generator/src/main/resources/go/utils.mustache index 602eaf30c1df..1907ea5c1eb7 100644 --- a/modules/openapi-generator/src/main/resources/go/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go/utils.mustache @@ -2,7 +2,9 @@ package {{packageName}} import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -336,3 +338,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/samples/client/echo_api/go-external-refs/client.go b/samples/client/echo_api/go-external-refs/client.go index 6c4adba09560..b725fb3f6d9c 100644 --- a/samples/client/echo_api/go-external-refs/client.go +++ b/samples/client/echo_api/go-external-refs/client.go @@ -519,18 +519,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/client/echo_api/go-external-refs/utils.go b/samples/client/echo_api/go-external-refs/utils.go index 937ed9e7336e..55defd54b945 100644 --- a/samples/client/echo_api/go-external-refs/utils.go +++ b/samples/client/echo_api/go-external-refs/utils.go @@ -12,7 +12,9 @@ Contact: team@openapitools.org package openapi import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -346,3 +348,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/samples/client/echo_api/go/client.go b/samples/client/echo_api/go/client.go index 6c4adba09560..b725fb3f6d9c 100644 --- a/samples/client/echo_api/go/client.go +++ b/samples/client/echo_api/go/client.go @@ -519,18 +519,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/client/echo_api/go/utils.go b/samples/client/echo_api/go/utils.go index 937ed9e7336e..55defd54b945 100644 --- a/samples/client/echo_api/go/utils.go +++ b/samples/client/echo_api/go/utils.go @@ -12,7 +12,9 @@ Contact: team@openapitools.org package openapi import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -346,3 +348,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file 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 7a054ad52eb7..392f159a7e89 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 @@ -490,18 +490,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/client/others/go/allof_multiple_ref_and_discriminator/utils.go b/samples/client/others/go/allof_multiple_ref_and_discriminator/utils.go index 5bcb22982429..0a765d499c44 100644 --- a/samples/client/others/go/allof_multiple_ref_and_discriminator/utils.go +++ b/samples/client/others/go/allof_multiple_ref_and_discriminator/utils.go @@ -11,7 +11,9 @@ API version: 1.0.0 package openapi import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/samples/client/others/go/oneof-anyof-required/client.go b/samples/client/others/go/oneof-anyof-required/client.go index 7a054ad52eb7..392f159a7e89 100644 --- a/samples/client/others/go/oneof-anyof-required/client.go +++ b/samples/client/others/go/oneof-anyof-required/client.go @@ -490,18 +490,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/client/others/go/oneof-anyof-required/utils.go b/samples/client/others/go/oneof-anyof-required/utils.go index 5bcb22982429..0a765d499c44 100644 --- a/samples/client/others/go/oneof-anyof-required/utils.go +++ b/samples/client/others/go/oneof-anyof-required/utils.go @@ -11,7 +11,9 @@ API version: 1.0.0 package openapi import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index c56879d3acae..ec2ac351d050 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -525,18 +525,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/client/petstore/go/go-petstore/utils.go b/samples/client/petstore/go/go-petstore/utils.go index 5e3318857b3e..a2dcd6eac4b2 100644 --- a/samples/client/petstore/go/go-petstore/utils.go +++ b/samples/client/petstore/go/go-petstore/utils.go @@ -11,7 +11,9 @@ API version: 1.0.0 package petstore import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file 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 33da123ab61c..1e3b4bd14c0c 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 @@ -493,18 +493,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/utils.go b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/utils.go index c3a01ea66050..fa0b330b65a1 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/utils.go +++ b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/utils.go @@ -11,7 +11,9 @@ API version: 1.0.0 package x_auth_id_alias import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file 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 3174a5c333ef..37305e6f228e 100644 --- a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go +++ b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/client.go @@ -505,18 +505,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/utils.go b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/utils.go index 794f72111af5..beea36a80819 100644 --- a/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/utils.go +++ b/samples/openapi3/client/petstore/go-petstore-generateMarshalJSON-false/utils.go @@ -11,7 +11,9 @@ API version: 1.0.0 package petstore import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index 5950806508b2..42c1dfd04952 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -543,18 +543,6 @@ func addFile(w *multipart.Writer, fieldName, path string) error { return err } -// Prevent trying to import "fmt" -func reportError(format string, a ...interface{}) error { - return fmt.Errorf(format, a...) -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - // Set request body from an interface{} func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { if bodyBuf == nil { diff --git a/samples/openapi3/client/petstore/go/go-petstore/utils.go b/samples/openapi3/client/petstore/go/go-petstore/utils.go index 5e3318857b3e..a2dcd6eac4b2 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go/go-petstore/utils.go @@ -11,7 +11,9 @@ API version: 1.0.0 package petstore import ( + "bytes" "encoding/json" + "fmt" "reflect" "time" ) @@ -345,3 +347,15 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/samples/server/petstore/go-gin-api-server/go.sum b/samples/server/petstore/go-gin-api-server/go.sum index 5a6c9b3832cc..3da8f838b873 100644 --- a/samples/server/petstore/go-gin-api-server/go.sum +++ b/samples/server/petstore/go-gin-api-server/go.sum @@ -76,24 +76,29 @@ golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=