From f8840d0d857fd8a6fd711e66186d78737b584da9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 08:54:25 +0000 Subject: [PATCH 01/13] Initial plan From 339c6020e176104e19f9b3d84e9e1c09fa9d5220 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 09:25:03 +0000 Subject: [PATCH 02/13] Update AWS Go SDK from v1 to v2 in Go client templates Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../src/main/resources/go/client.mustache | 27 ++++++++++--------- .../src/main/resources/go/go.mod.mustache | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 0bff8913d4a5..397d076dce1c 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -27,8 +27,9 @@ import ( "golang.org/x/oauth2" {{/hasOAuthMethods}} {{#withAWSV4Signature}} - awsv4 "github.com/aws/aws-sdk-go/aws/signer/v4" - awscredentials "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go-v2/aws" + v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" + "github.com/aws/aws-sdk-go-v2/credentials" {{/withAWSV4Signature}} ) @@ -458,15 +459,9 @@ func (c *APIClient) prepareRequest( {{#withAWSV4Signature}} // AWS Signature v4 Authentication if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { - creds := awscredentials.NewStaticCredentials(auth.AccessKey, auth.SecretKey, auth.SessionToken) - signer := awsv4.NewSigner(creds) - var reader *strings.Reader - if body == nil { - reader = strings.NewReader("") - } else { - reader = strings.NewReader(body.String()) - } - + creds := credentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) + signer := v4.NewSigner() + // Define default values for region and service to maintain backward compatibility region := auth.Region if region == "" { @@ -477,8 +472,14 @@ func (c *APIClient) prepareRequest( service = "oapi" } - timestamp := time.Now() - _, err := signer.Sign(localVarRequest, reader, service, region, timestamp) + // Create AWS config with credentials + cfg := aws.Config{ + Region: region, + Credentials: creds, + } + + // Sign the request + err := signer.SignHTTP(ctx, cfg.Credentials, localVarRequest, "", service, region, time.Now()) if err != nil { return nil, err } diff --git a/modules/openapi-generator/src/main/resources/go/go.mod.mustache b/modules/openapi-generator/src/main/resources/go/go.mod.mustache index c094d63543c3..4ffa7f9dcbd7 100644 --- a/modules/openapi-generator/src/main/resources/go/go.mod.mustache +++ b/modules/openapi-generator/src/main/resources/go/go.mod.mustache @@ -8,7 +8,7 @@ require ( golang.org/x/oauth2 v0.27.0 {{/hasOAuthMethods}} {{#withAWSV4Signature}} - github.com/aws/aws-sdk-go v1.34.14 + github.com/aws/aws-sdk-go-v2 v1.30.3 {{/withAWSV4Signature}} {{#importValidator}} gopkg.in/validator.v2 v2.0.1 From 267e9fb87384ddfe0515d095755dacbfa7df61cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 09:26:58 +0000 Subject: [PATCH 03/13] Final validation: AWS SDK v2 integration working correctly Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../client/petstore/go/go-petstore/go.mod | 10 ++++++- .../client/petstore/go/go-petstore/go.sum | 28 +++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/samples/openapi3/client/petstore/go/go-petstore/go.mod b/samples/openapi3/client/petstore/go/go-petstore/go.mod index a3f72d6e8bd9..5a24fd06ce77 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/go.mod +++ b/samples/openapi3/client/petstore/go/go-petstore/go.mod @@ -1,9 +1,17 @@ module github.com/GIT_USER_ID/GIT_REPO_ID -go 1.23 +go 1.23.0 + +toolchain go1.24.5 require ( github.com/stretchr/testify v1.10.0 golang.org/x/oauth2 v0.27.0 gopkg.in/validator.v2 v2.0.1 ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/samples/openapi3/client/petstore/go/go-petstore/go.sum b/samples/openapi3/client/petstore/go/go-petstore/go.sum index c97062a690ca..f83d2f320fbc 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/go.sum +++ b/samples/openapi3/client/petstore/go/go-petstore/go.sum @@ -1,15 +1,21 @@ -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +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/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY= gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 0586cd0961b8e2cee893947358d8824fe4f785b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 09:52:34 +0000 Subject: [PATCH 04/13] Fix AWS v4 signature implementation: retrieve credentials properly from provider Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../src/main/resources/go/client.mustache | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 397d076dce1c..bb1e033f80ca 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -27,7 +27,6 @@ import ( "golang.org/x/oauth2" {{/hasOAuthMethods}} {{#withAWSV4Signature}} - "github.com/aws/aws-sdk-go-v2/aws" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/aws/aws-sdk-go-v2/credentials" {{/withAWSV4Signature}} @@ -459,7 +458,7 @@ func (c *APIClient) prepareRequest( {{#withAWSV4Signature}} // AWS Signature v4 Authentication if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { - creds := credentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) + credsProvider := credentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) signer := v4.NewSigner() // Define default values for region and service to maintain backward compatibility @@ -472,14 +471,14 @@ func (c *APIClient) prepareRequest( service = "oapi" } - // Create AWS config with credentials - cfg := aws.Config{ - Region: region, - Credentials: creds, + // Retrieve credentials from provider + creds, err := credsProvider.Retrieve(ctx) + if err != nil { + return nil, err } - // Sign the request - err := signer.SignHTTP(ctx, cfg.Credentials, localVarRequest, "", service, region, time.Now()) + // Sign the request (empty string tells signer to compute payload hash automatically) + err = signer.SignHTTP(ctx, creds, localVarRequest, "", service, region, time.Now()) if err != nil { return nil, err } From c39359a5abc10201ea599132318051eead1a299f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:28:01 +0000 Subject: [PATCH 05/13] Fix AWS v4 signature payload hash: properly compute SHA-256 hash for request body Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../src/main/resources/go/client.mustache | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index bb1e033f80ca..27fb889b48fd 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -27,6 +27,8 @@ import ( "golang.org/x/oauth2" {{/hasOAuthMethods}} {{#withAWSV4Signature}} + "crypto/sha256" + "encoding/hex" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/aws/aws-sdk-go-v2/credentials" {{/withAWSV4Signature}} @@ -477,8 +479,26 @@ func (c *APIClient) prepareRequest( return nil, err } - // Sign the request (empty string tells signer to compute payload hash automatically) - err = signer.SignHTTP(ctx, creds, localVarRequest, "", service, region, time.Now()) + // Compute payload hash + var payloadHash string + if localVarRequest.Body != nil { + // Read the body content + bodyBytes, err := io.ReadAll(localVarRequest.Body) + if err != nil { + return nil, err + } + // Restore the body for the actual request + localVarRequest.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + // Compute SHA-256 hash of the body + hash := sha256.Sum256(bodyBytes) + payloadHash = hex.EncodeToString(hash[:]) + } else { + // Use empty string hash for requests with no payload + payloadHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + } + + // Sign the request with the computed payload hash + err = signer.SignHTTP(ctx, creds, localVarRequest, payloadHash, service, region, time.Now()) if err != nil { return nil, err } From 86979f80d3598deb3d0139de27bab1ee8ad95e60 Mon Sep 17 00:00:00 2001 From: Dennis Mouwen Date: Mon, 28 Jul 2025 16:29:05 +0200 Subject: [PATCH 06/13] Implement proper payload hashing --- .../src/main/resources/go/client.mustache | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index bb1e033f80ca..45de4ccb95b7 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -471,14 +471,21 @@ func (c *APIClient) prepareRequest( service = "oapi" } - // Retrieve credentials from provider - creds, err := credsProvider.Retrieve(ctx) - if err != nil { - return nil, err + // Compute payload hash from the request body + var payloadHash string + if body == nil { + // Empty body + hash := sha256.Sum256([]byte("")) + payloadHash = hex.EncodeToString(hash[:]) + } else { + // Hash the actual body content + bodyBytes := []byte(body.String()) + hash := sha256.Sum256(bodyBytes) + payloadHash = hex.EncodeToString(hash[:]) } - // Sign the request (empty string tells signer to compute payload hash automatically) - err = signer.SignHTTP(ctx, creds, localVarRequest, "", service, region, time.Now()) + // Sign the request with the computed payload hash + err = signer.SignHTTP(ctx, creds, localVarRequest, payloadHash, service, region, time.Now()) if err != nil { return nil, err } From baee74443c7da767f00929f0ce90141ae6acdba6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:33:48 +0000 Subject: [PATCH 07/13] Revert go.sum file to original state as requested Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../client/petstore/go/go-petstore/go.sum | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/samples/openapi3/client/petstore/go/go-petstore/go.sum b/samples/openapi3/client/petstore/go/go-petstore/go.sum index f83d2f320fbc..c97062a690ca 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/go.sum +++ b/samples/openapi3/client/petstore/go/go-petstore/go.sum @@ -1,21 +1,15 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= -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/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY= gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 96cd6ac392123c484dfebced1f982d0ffa1770a2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 28 Jul 2025 14:39:55 +0000 Subject: [PATCH 08/13] Revert go.mod and rename import alias from v4 back to awsv4 Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../openapi-generator/src/main/resources/go/client.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 45de4ccb95b7..ae4aef4b41e9 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -27,7 +27,7 @@ import ( "golang.org/x/oauth2" {{/hasOAuthMethods}} {{#withAWSV4Signature}} - v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" + awsv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/aws/aws-sdk-go-v2/credentials" {{/withAWSV4Signature}} ) @@ -459,7 +459,7 @@ func (c *APIClient) prepareRequest( // AWS Signature v4 Authentication if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { credsProvider := credentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) - signer := v4.NewSigner() + signer := awsv4.NewSigner() // Define default values for region and service to maintain backward compatibility region := auth.Region From 0405017f8babb623649a5d93e83d1b22270dcf3f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Jul 2025 07:10:33 +0000 Subject: [PATCH 09/13] Revert go.mod file to original state removing all changes Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- samples/openapi3/client/petstore/go/go-petstore/go.mod | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/samples/openapi3/client/petstore/go/go-petstore/go.mod b/samples/openapi3/client/petstore/go/go-petstore/go.mod index 5a24fd06ce77..a3f72d6e8bd9 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/go.mod +++ b/samples/openapi3/client/petstore/go/go-petstore/go.mod @@ -1,17 +1,9 @@ module github.com/GIT_USER_ID/GIT_REPO_ID -go 1.23.0 - -toolchain go1.24.5 +go 1.23 require ( github.com/stretchr/testify v1.10.0 golang.org/x/oauth2 v0.27.0 gopkg.in/validator.v2 v2.0.1 ) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) From 1e9712b37504c7f76b4cfe11829194f7b5765520 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Jul 2025 07:16:44 +0000 Subject: [PATCH 10/13] Rename credentials import to awscredentials alias as requested Co-authored-by: dennismouwen-eye <107839749+dennismouwen-eye@users.noreply.github.com> --- .../openapi-generator/src/main/resources/go/client.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index ae4aef4b41e9..dea03f61e7f1 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -28,7 +28,7 @@ import ( {{/hasOAuthMethods}} {{#withAWSV4Signature}} awsv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" - "github.com/aws/aws-sdk-go-v2/credentials" + awscredentials "github.com/aws/aws-sdk-go-v2/credentials" {{/withAWSV4Signature}} ) @@ -458,7 +458,7 @@ func (c *APIClient) prepareRequest( {{#withAWSV4Signature}} // AWS Signature v4 Authentication if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { - credsProvider := credentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) + credsProvider := awscredentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) signer := awsv4.NewSigner() // Define default values for region and service to maintain backward compatibility From da0bedae015b46dc70f0b6bc41fbea87f619f89e Mon Sep 17 00:00:00 2001 From: Dennis Mouwen Date: Tue, 29 Jul 2025 10:21:41 +0200 Subject: [PATCH 11/13] Fix spacing --- modules/openapi-generator/src/main/resources/go/client.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index dea03f61e7f1..cb2d4e9d214f 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -28,7 +28,7 @@ import ( {{/hasOAuthMethods}} {{#withAWSV4Signature}} awsv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" - awscredentials "github.com/aws/aws-sdk-go-v2/credentials" + awscredentials "github.com/aws/aws-sdk-go-v2/credentials" {{/withAWSV4Signature}} ) From c5ae6b89f94d152183a3f74da7a2bc4113a03167 Mon Sep 17 00:00:00 2001 From: Dennis Mouwen Date: Tue, 29 Jul 2025 10:27:13 +0200 Subject: [PATCH 12/13] Fix credentials and imports --- .../src/main/resources/go/client.mustache | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index cb2d4e9d214f..307aa0acc250 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -29,6 +29,8 @@ import ( {{#withAWSV4Signature}} awsv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" awscredentials "github.com/aws/aws-sdk-go-v2/credentials" + "crypto/sha256" + "encoding/hex" {{/withAWSV4Signature}} ) @@ -459,8 +461,11 @@ func (c *APIClient) prepareRequest( // AWS Signature v4 Authentication if auth, ok := ctx.Value(ContextAWSv4).(AWSv4); ok { credsProvider := awscredentials.NewStaticCredentialsProvider(auth.AccessKey, auth.SecretKey, auth.SessionToken) - signer := awsv4.NewSigner() - + creds, err := credsProvider.Retrieve(ctx) + if err != nil { + return nil, err + } + // Define default values for region and service to maintain backward compatibility region := auth.Region if region == "" { @@ -485,6 +490,7 @@ func (c *APIClient) prepareRequest( } // Sign the request with the computed payload hash + signer := awsv4.NewSigner() err = signer.SignHTTP(ctx, creds, localVarRequest, payloadHash, service, region, time.Now()) if err != nil { return nil, err From 193fecb646c34dbfe47404e0f763ac90dcfedfda Mon Sep 17 00:00:00 2001 From: Dennis Mouwen Date: Tue, 29 Jul 2025 10:28:31 +0200 Subject: [PATCH 13/13] Update aws sdk to latest version --- modules/openapi-generator/src/main/resources/go/go.mod.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/go/go.mod.mustache b/modules/openapi-generator/src/main/resources/go/go.mod.mustache index 4ffa7f9dcbd7..30ac351f4231 100644 --- a/modules/openapi-generator/src/main/resources/go/go.mod.mustache +++ b/modules/openapi-generator/src/main/resources/go/go.mod.mustache @@ -8,7 +8,7 @@ require ( golang.org/x/oauth2 v0.27.0 {{/hasOAuthMethods}} {{#withAWSV4Signature}} - github.com/aws/aws-sdk-go-v2 v1.30.3 + github.com/aws/aws-sdk-go-v2 v1.37.0 {{/withAWSV4Signature}} {{#importValidator}} gopkg.in/validator.v2 v2.0.1