diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 62f75508baef..7b0fcefca664 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -127,7 +127,7 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { // Check the type is as expected. if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) } return nil } @@ -514,7 +514,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e } if bodyBuf.Len() == 0 { - err = fmt.Errorf("Invalid body type %s\n", contentType) + err = fmt.Errorf("invalid body type %s\n", contentType) return nil, err } return bodyBuf, nil diff --git a/modules/openapi-generator/src/main/resources/go/configuration.mustache b/modules/openapi-generator/src/main/resources/go/configuration.mustache index 610f9edc5d27..088e9202cf86 100644 --- a/modules/openapi-generator/src/main/resources/go/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/go/configuration.mustache @@ -207,7 +207,7 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { // URL formats template on a index using given variables func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { if index < 0 || len(sc) <= index { - return "", fmt.Errorf("Index %v out of range %v", index, len(sc)-1) + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) } server := sc[index] url := server.URL @@ -222,7 +222,7 @@ func (sc ServerConfigurations) URL(index int, variables map[string]string) (stri } } if !found { - return "", fmt.Errorf("The variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) } url = strings.Replace(url, "{"+name+"}", value, -1) } else { diff --git a/modules/openapi-generator/src/main/resources/go/model_anyof.mustache b/modules/openapi-generator/src/main/resources/go/model_anyof.mustache index f1d8c57c85ff..3b221d80fb61 100644 --- a/modules/openapi-generator/src/main/resources/go/model_anyof.mustache +++ b/modules/openapi-generator/src/main/resources/go/model_anyof.mustache @@ -22,7 +22,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { var jsonDict map[string]interface{} err = json.Unmarshal(data, &jsonDict) if err != nil { - return fmt.Errorf("Failed to unmarshal JSON into map for the discriminator lookup.") + return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") } {{/-first}} @@ -59,7 +59,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { } {{/anyOf}} - return fmt.Errorf("Data failed to match schemas in anyOf({{classname}})") + return fmt.Errorf("data failed to match schemas in anyOf({{classname}})") } // Marshal data from the first non-nil pointers in the struct to JSON 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 14bc3ada757e..3f70f611683a 100644 --- a/modules/openapi-generator/src/main/resources/go/model_oneof.mustache +++ b/modules/openapi-generator/src/main/resources/go/model_oneof.mustache @@ -33,7 +33,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { var jsonDict map[string]interface{} err = newStrictDecoder(data).Decode(&jsonDict) if err != nil { - return fmt.Errorf("Failed to unmarshal JSON into map for the discriminator lookup.") + return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") } {{/-first}} @@ -45,7 +45,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { return nil // data stored in dst.{{{modelName}}}, return on the first match } else { dst.{{{modelName}}} = nil - return fmt.Errorf("Failed to unmarshal {{classname}} as {{{modelName}}}: %s", err.Error()) + return fmt.Errorf("failed to unmarshal {{classname}} as {{{modelName}}}: %s", err.Error()) } } @@ -75,11 +75,11 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil {{/oneOf}} - return fmt.Errorf("Data matches more than one schema in oneOf({{classname}})") + return fmt.Errorf("data matches more than one schema in oneOf({{classname}})") } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf({{classname}})") + return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") } {{/discriminator}} {{/useOneOfDiscriminatorLookup}} @@ -106,11 +106,11 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error { dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil {{/oneOf}} - return fmt.Errorf("Data matches more than one schema in oneOf({{classname}})") + return fmt.Errorf("data matches more than one schema in oneOf({{classname}})") } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf({{classname}})") + return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") } {{/useOneOfDiscriminatorLookup}} } diff --git a/modules/openapi-generator/src/main/resources/go/signing.mustache b/modules/openapi-generator/src/main/resources/go/signing.mustache index d8c5b376e9e6..6400d0265ea4 100644 --- a/modules/openapi-generator/src/main/resources/go/signing.mustache +++ b/modules/openapi-generator/src/main/resources/go/signing.mustache @@ -126,26 +126,26 @@ func (h *HttpSignatureAuth) SetPrivateKey(privateKey string) error { // are invalid. func (h *HttpSignatureAuth) ContextWithValue(ctx context.Context) (context.Context, error) { if h.KeyId == "" { - return nil, fmt.Errorf("Key ID must be specified") + return nil, fmt.Errorf("key ID must be specified") } if h.PrivateKeyPath == "" && h.privateKey == nil { - return nil, fmt.Errorf("Private key path must be specified") + return nil, fmt.Errorf("private key path must be specified") } if _, ok := supportedSigningSchemes[h.SigningScheme]; !ok { - return nil, fmt.Errorf("Invalid signing scheme: '%v'", h.SigningScheme) + return nil, fmt.Errorf("invalid signing scheme: '%v'", h.SigningScheme) } m := make(map[string]bool) for _, h := range h.SignedHeaders { if strings.EqualFold(h, HttpHeaderAuthorization) { - return nil, fmt.Errorf("Signed headers cannot include the 'Authorization' header") + return nil, fmt.Errorf("signed headers cannot include the 'Authorization' header") } m[h] = true } if len(m) != len(h.SignedHeaders) { - return nil, fmt.Errorf("List of signed headers cannot have duplicate names") + return nil, fmt.Errorf("list of signed headers cannot have duplicate names") } if h.SignatureMaxValidity < 0 { - return nil, fmt.Errorf("Signature max validity must be a positive value") + return nil, fmt.Errorf("signature max validity must be a positive value") } if err := h.loadPrivateKey(); err != nil { return nil, err @@ -168,7 +168,7 @@ func (h *HttpSignatureAuth) GetPublicKey() (crypto.PublicKey, error) { default: // Do not change '%T' to anything else such as '%v'! // The value of the private key must not be returned. - return nil, fmt.Errorf("Unsupported key: %T", h.privateKey) + return nil, fmt.Errorf("unsupported key: %T", h.privateKey) } } @@ -181,7 +181,7 @@ func (h *HttpSignatureAuth) loadPrivateKey() (err error) { var file *os.File file, err = os.Open(h.PrivateKeyPath) if err != nil { - return fmt.Errorf("Cannot load private key '%s'. Error: %v", h.PrivateKeyPath, err) + return fmt.Errorf("cannot load private key '%s'. Error: %v", h.PrivateKeyPath, err) } defer func() { err = file.Close() @@ -199,7 +199,7 @@ func (h *HttpSignatureAuth) parsePrivateKey(priv []byte) error { pemBlock, _ := pem.Decode(priv) if pemBlock == nil { // No PEM data has been found. - return fmt.Errorf("File '%s' does not contain PEM data", h.PrivateKeyPath) + return fmt.Errorf("file '%s' does not contain PEM data", h.PrivateKeyPath) } var privKey []byte var err error @@ -225,7 +225,7 @@ func (h *HttpSignatureAuth) parsePrivateKey(priv []byte) error { return err } default: - return fmt.Errorf("Key '%s' is not supported", pemBlock.Type) + return fmt.Errorf("key '%s' is not supported", pemBlock.Type) } return nil } @@ -248,7 +248,7 @@ func SignRequest( auth HttpSignatureAuth) error { if auth.privateKey == nil { - return fmt.Errorf("Private key is not set") + return fmt.Errorf("private key is not set") } now := time.Now() date := now.UTC().Format(http.TimeFormat) @@ -262,7 +262,7 @@ func SignRequest( var expiresUnix float64 if auth.SignatureMaxValidity < 0 { - return fmt.Errorf("Signature validity must be a positive value") + return fmt.Errorf("signature validity must be a positive value") } if auth.SignatureMaxValidity > 0 { e := now.Add(auth.SignatureMaxValidity) @@ -278,10 +278,10 @@ func SignRequest( h = crypto.SHA256 prefix = "SHA-256=" default: - return fmt.Errorf("Unsupported signature scheme: %v", auth.SigningScheme) + return fmt.Errorf("unsupported signature scheme: %v", auth.SigningScheme) } if !h.Available() { - return fmt.Errorf("Hash '%v' is not available", h) + return fmt.Errorf("hash '%v' is not available", h) } // Build the "(request-target)" signature header. @@ -308,7 +308,7 @@ func SignRequest( m[h] = true } if len(m) != len(signedHeaders) { - return fmt.Errorf("List of signed headers must not have any duplicates") + return fmt.Errorf("list of signed headers must not have any duplicates") } hasCreatedParameter := false hasExpiresParameter := false @@ -317,7 +317,7 @@ func SignRequest( var value string switch header { case strings.ToLower(HttpHeaderAuthorization): - return fmt.Errorf("Cannot include the 'Authorization' header as a signed header.") + return fmt.Errorf("cannot include the 'Authorization' header as a signed header") case HttpSignatureParameterRequestTarget: value = requestTarget case HttpSignatureParameterCreated: @@ -325,7 +325,7 @@ func SignRequest( hasCreatedParameter = true case HttpSignatureParameterExpires: if auth.SignatureMaxValidity.Nanoseconds() == 0 { - return fmt.Errorf("Cannot set '(expires)' signature parameter. SignatureMaxValidity is not configured.") + return fmt.Errorf("cannot set '(expires)' signature parameter. SignatureMaxValidity is not configured") } value = fmt.Sprintf("%.3f", expiresUnix) hasExpiresParameter = true @@ -361,7 +361,7 @@ func SignRequest( if v, ok = r.Header[canonicalHeader]; !ok { // If a header specified in the headers parameter cannot be matched with // a provided header in the message, the implementation MUST produce an error. - return fmt.Errorf("Header '%s' does not exist in the request", canonicalHeader) + return fmt.Errorf("header '%s' does not exist in the request", canonicalHeader) } // If there are multiple instances of the same header field, all // header field values associated with the header field MUST be @@ -376,7 +376,7 @@ func SignRequest( fmt.Fprintf(&sb, "%s: %s", header, value) } if expiresUnix != 0 && !hasExpiresParameter { - return fmt.Errorf("SignatureMaxValidity is specified, but '(expired)' parameter is not present") + return fmt.Errorf("signatureMaxValidity is specified, but '(expired)' parameter is not present") } msg := []byte(sb.String()) msgHash := h.New() @@ -394,14 +394,14 @@ func SignRequest( case "", HttpSigningAlgorithmRsaPSS: signature, err = rsa.SignPSS(rand.Reader, key, h, d, nil) default: - return fmt.Errorf("Unsupported signing algorithm: '%s'", auth.SigningAlgorithm) + return fmt.Errorf("unsupported signing algorithm: '%s'", auth.SigningAlgorithm) } case *ecdsa.PrivateKey: signature, err = key.Sign(rand.Reader, d, h) case ed25519.PrivateKey: // requires go 1.13 signature, err = key.Sign(rand.Reader, msg, crypto.Hash(0)) default: - return fmt.Errorf("Unsupported private key") + return fmt.Errorf("unsupported private key") } if err != nil { return err diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index f872380df96a..233c9ae5f6a3 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -135,7 +135,7 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { // Check the type is as expected. if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) } return nil } @@ -474,7 +474,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e } if bodyBuf.Len() == 0 { - err = fmt.Errorf("Invalid body type %s\n", contentType) + err = fmt.Errorf("invalid body type %s\n", contentType) return nil, err } return bodyBuf, nil diff --git a/samples/client/petstore/go/go-petstore/configuration.go b/samples/client/petstore/go/go-petstore/configuration.go index 326eb245319e..94d3b3bc4f97 100644 --- a/samples/client/petstore/go/go-petstore/configuration.go +++ b/samples/client/petstore/go/go-petstore/configuration.go @@ -123,7 +123,7 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { // URL formats template on a index using given variables func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { if index < 0 || len(sc) <= index { - return "", fmt.Errorf("Index %v out of range %v", index, len(sc)-1) + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) } server := sc[index] url := server.URL @@ -138,7 +138,7 @@ func (sc ServerConfigurations) URL(index int, variables map[string]string) (stri } } if !found { - return "", fmt.Errorf("The variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) } url = strings.Replace(url, "{"+name+"}", value, -1) } else { 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 547180d6b63e..d9197c7bdb26 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 @@ -120,7 +120,7 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { // Check the type is as expected. if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) } return nil } @@ -459,7 +459,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e } if bodyBuf.Len() == 0 { - err = fmt.Errorf("Invalid body type %s\n", contentType) + err = fmt.Errorf("invalid body type %s\n", contentType) return nil, err } return bodyBuf, nil diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/configuration.go b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/configuration.go index 69e73c4ffe0c..a8b3ade6ec50 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/configuration.go +++ b/samples/openapi3/client/extensions/x-auth-id-alias/go-experimental/configuration.go @@ -156,7 +156,7 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { // URL formats template on a index using given variables func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { if index < 0 || len(sc) <= index { - return "", fmt.Errorf("Index %v out of range %v", index, len(sc)-1) + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) } server := sc[index] url := server.URL @@ -171,7 +171,7 @@ func (sc ServerConfigurations) URL(index int, variables map[string]string) (stri } } if !found { - return "", fmt.Errorf("The variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) } url = strings.Replace(url, "{"+name+"}", value, -1) } else { diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index c6d7fabcb2ef..271e9df22d00 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -138,7 +138,7 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { // Check the type is as expected. if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) } return nil } @@ -487,7 +487,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e } if bodyBuf.Len() == 0 { - err = fmt.Errorf("Invalid body type %s\n", contentType) + err = fmt.Errorf("invalid body type %s\n", contentType) return nil, err } return bodyBuf, nil diff --git a/samples/openapi3/client/petstore/go/go-petstore/configuration.go b/samples/openapi3/client/petstore/go/go-petstore/configuration.go index dc41bdcfc29d..10c6f27a5834 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/configuration.go +++ b/samples/openapi3/client/petstore/go/go-petstore/configuration.go @@ -180,7 +180,7 @@ func (c *Configuration) AddDefaultHeader(key string, value string) { // URL formats template on a index using given variables func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { if index < 0 || len(sc) <= index { - return "", fmt.Errorf("Index %v out of range %v", index, len(sc)-1) + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) } server := sc[index] url := server.URL @@ -195,7 +195,7 @@ func (sc ServerConfigurations) URL(index int, variables map[string]string) (stri } } if !found { - return "", fmt.Errorf("The variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) } url = strings.Replace(url, "{"+name+"}", value, -1) } else { 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 74b0aa52b3c3..de6c7867502f 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_fruit.go @@ -71,11 +71,11 @@ func (dst *Fruit) UnmarshalJSON(data []byte) error { dst.Apple = nil dst.Banana = nil - return fmt.Errorf("Data matches more than one schema in oneOf(Fruit)") + return fmt.Errorf("data matches more than one schema in oneOf(Fruit)") } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(Fruit)") + return fmt.Errorf("data failed to match schemas in oneOf(Fruit)") } } 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 82ff8714324a..7dccf1d81280 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 @@ -71,11 +71,11 @@ func (dst *FruitReq) UnmarshalJSON(data []byte) error { dst.AppleReq = nil dst.BananaReq = nil - return fmt.Errorf("Data matches more than one schema in oneOf(FruitReq)") + return fmt.Errorf("data matches more than one schema in oneOf(FruitReq)") } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(FruitReq)") + return fmt.Errorf("data failed to match schemas in oneOf(FruitReq)") } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go b/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go index bc1023eacaf4..fbed807427ea 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_gm_fruit.go @@ -50,7 +50,7 @@ func (dst *GmFruit) UnmarshalJSON(data []byte) error { dst.Banana = nil } - return fmt.Errorf("Data failed to match schemas in anyOf(GmFruit)") + return fmt.Errorf("data failed to match schemas in anyOf(GmFruit)") } // Marshal data from the first non-nil pointers in the struct to JSON 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 7f899aa6db7e..77a58b5d33be 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_mammal.go @@ -71,11 +71,11 @@ func (dst *Mammal) UnmarshalJSON(data []byte) error { dst.Whale = nil dst.Zebra = nil - return fmt.Errorf("Data matches more than one schema in oneOf(Mammal)") + return fmt.Errorf("data matches more than one schema in oneOf(Mammal)") } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(Mammal)") + return fmt.Errorf("data failed to match schemas in oneOf(Mammal)") } } 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 dd008dfc1502..fc8ba677f68a 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 @@ -93,11 +93,11 @@ func (dst *OneOfPrimitiveType) UnmarshalJSON(data []byte) error { dst.ArrayOfString = nil dst.Int32 = nil - return fmt.Errorf("Data matches more than one schema in oneOf(OneOfPrimitiveType)") + return fmt.Errorf("data matches more than one schema in oneOf(OneOfPrimitiveType)") } else if match == 1 { return nil // exactly one match } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(OneOfPrimitiveType)") + return fmt.Errorf("data failed to match schemas in oneOf(OneOfPrimitiveType)") } } diff --git a/samples/openapi3/client/petstore/go/go-petstore/signing.go b/samples/openapi3/client/petstore/go/go-petstore/signing.go index d6dfdbb50f95..6a6a756ff147 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/signing.go +++ b/samples/openapi3/client/petstore/go/go-petstore/signing.go @@ -135,26 +135,26 @@ func (h *HttpSignatureAuth) SetPrivateKey(privateKey string) error { // are invalid. func (h *HttpSignatureAuth) ContextWithValue(ctx context.Context) (context.Context, error) { if h.KeyId == "" { - return nil, fmt.Errorf("Key ID must be specified") + return nil, fmt.Errorf("key ID must be specified") } if h.PrivateKeyPath == "" && h.privateKey == nil { - return nil, fmt.Errorf("Private key path must be specified") + return nil, fmt.Errorf("private key path must be specified") } if _, ok := supportedSigningSchemes[h.SigningScheme]; !ok { - return nil, fmt.Errorf("Invalid signing scheme: '%v'", h.SigningScheme) + return nil, fmt.Errorf("invalid signing scheme: '%v'", h.SigningScheme) } m := make(map[string]bool) for _, h := range h.SignedHeaders { if strings.EqualFold(h, HttpHeaderAuthorization) { - return nil, fmt.Errorf("Signed headers cannot include the 'Authorization' header") + return nil, fmt.Errorf("signed headers cannot include the 'Authorization' header") } m[h] = true } if len(m) != len(h.SignedHeaders) { - return nil, fmt.Errorf("List of signed headers cannot have duplicate names") + return nil, fmt.Errorf("list of signed headers cannot have duplicate names") } if h.SignatureMaxValidity < 0 { - return nil, fmt.Errorf("Signature max validity must be a positive value") + return nil, fmt.Errorf("signature max validity must be a positive value") } if err := h.loadPrivateKey(); err != nil { return nil, err @@ -177,7 +177,7 @@ func (h *HttpSignatureAuth) GetPublicKey() (crypto.PublicKey, error) { default: // Do not change '%T' to anything else such as '%v'! // The value of the private key must not be returned. - return nil, fmt.Errorf("Unsupported key: %T", h.privateKey) + return nil, fmt.Errorf("unsupported key: %T", h.privateKey) } } @@ -190,7 +190,7 @@ func (h *HttpSignatureAuth) loadPrivateKey() (err error) { var file *os.File file, err = os.Open(h.PrivateKeyPath) if err != nil { - return fmt.Errorf("Cannot load private key '%s'. Error: %v", h.PrivateKeyPath, err) + return fmt.Errorf("cannot load private key '%s'. Error: %v", h.PrivateKeyPath, err) } defer func() { err = file.Close() @@ -208,7 +208,7 @@ func (h *HttpSignatureAuth) parsePrivateKey(priv []byte) error { pemBlock, _ := pem.Decode(priv) if pemBlock == nil { // No PEM data has been found. - return fmt.Errorf("File '%s' does not contain PEM data", h.PrivateKeyPath) + return fmt.Errorf("file '%s' does not contain PEM data", h.PrivateKeyPath) } var privKey []byte var err error @@ -234,7 +234,7 @@ func (h *HttpSignatureAuth) parsePrivateKey(priv []byte) error { return err } default: - return fmt.Errorf("Key '%s' is not supported", pemBlock.Type) + return fmt.Errorf("key '%s' is not supported", pemBlock.Type) } return nil } @@ -257,7 +257,7 @@ func SignRequest( auth HttpSignatureAuth) error { if auth.privateKey == nil { - return fmt.Errorf("Private key is not set") + return fmt.Errorf("private key is not set") } now := time.Now() date := now.UTC().Format(http.TimeFormat) @@ -271,7 +271,7 @@ func SignRequest( var expiresUnix float64 if auth.SignatureMaxValidity < 0 { - return fmt.Errorf("Signature validity must be a positive value") + return fmt.Errorf("signature validity must be a positive value") } if auth.SignatureMaxValidity > 0 { e := now.Add(auth.SignatureMaxValidity) @@ -287,10 +287,10 @@ func SignRequest( h = crypto.SHA256 prefix = "SHA-256=" default: - return fmt.Errorf("Unsupported signature scheme: %v", auth.SigningScheme) + return fmt.Errorf("unsupported signature scheme: %v", auth.SigningScheme) } if !h.Available() { - return fmt.Errorf("Hash '%v' is not available", h) + return fmt.Errorf("hash '%v' is not available", h) } // Build the "(request-target)" signature header. @@ -317,7 +317,7 @@ func SignRequest( m[h] = true } if len(m) != len(signedHeaders) { - return fmt.Errorf("List of signed headers must not have any duplicates") + return fmt.Errorf("list of signed headers must not have any duplicates") } hasCreatedParameter := false hasExpiresParameter := false @@ -326,7 +326,7 @@ func SignRequest( var value string switch header { case strings.ToLower(HttpHeaderAuthorization): - return fmt.Errorf("Cannot include the 'Authorization' header as a signed header.") + return fmt.Errorf("cannot include the 'Authorization' header as a signed header") case HttpSignatureParameterRequestTarget: value = requestTarget case HttpSignatureParameterCreated: @@ -334,7 +334,7 @@ func SignRequest( hasCreatedParameter = true case HttpSignatureParameterExpires: if auth.SignatureMaxValidity.Nanoseconds() == 0 { - return fmt.Errorf("Cannot set '(expires)' signature parameter. SignatureMaxValidity is not configured.") + return fmt.Errorf("cannot set '(expires)' signature parameter. SignatureMaxValidity is not configured") } value = fmt.Sprintf("%.3f", expiresUnix) hasExpiresParameter = true @@ -370,7 +370,7 @@ func SignRequest( if v, ok = r.Header[canonicalHeader]; !ok { // If a header specified in the headers parameter cannot be matched with // a provided header in the message, the implementation MUST produce an error. - return fmt.Errorf("Header '%s' does not exist in the request", canonicalHeader) + return fmt.Errorf("header '%s' does not exist in the request", canonicalHeader) } // If there are multiple instances of the same header field, all // header field values associated with the header field MUST be @@ -385,7 +385,7 @@ func SignRequest( fmt.Fprintf(&sb, "%s: %s", header, value) } if expiresUnix != 0 && !hasExpiresParameter { - return fmt.Errorf("SignatureMaxValidity is specified, but '(expired)' parameter is not present") + return fmt.Errorf("signatureMaxValidity is specified, but '(expired)' parameter is not present") } msg := []byte(sb.String()) msgHash := h.New() @@ -403,14 +403,14 @@ func SignRequest( case "", HttpSigningAlgorithmRsaPSS: signature, err = rsa.SignPSS(rand.Reader, key, h, d, nil) default: - return fmt.Errorf("Unsupported signing algorithm: '%s'", auth.SigningAlgorithm) + return fmt.Errorf("unsupported signing algorithm: '%s'", auth.SigningAlgorithm) } case *ecdsa.PrivateKey: signature, err = key.Sign(rand.Reader, d, h) case ed25519.PrivateKey: // requires go 1.13 signature, err = key.Sign(rand.Reader, msg, crypto.Hash(0)) default: - return fmt.Errorf("Unsupported private key") + return fmt.Errorf("unsupported private key") } if err != nil { return err diff --git a/samples/openapi3/client/petstore/go/http_signature_test.go b/samples/openapi3/client/petstore/go/http_signature_test.go index 104cd00f03ef..492de97b5255 100644 --- a/samples/openapi3/client/petstore/go/http_signature_test.go +++ b/samples/openapi3/client/petstore/go/http_signature_test.go @@ -650,7 +650,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) { authConfig = sw.HttpSignatureAuth{} _, err = authConfig.ContextWithValue(context.Background()) - if err == nil || !strings.Contains(err.Error(), "Key ID must be specified") { + if err == nil || !strings.Contains(err.Error(), "key ID must be specified") { t.Fatalf("Invalid configuration: %v", err) } @@ -658,7 +658,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) { KeyId: "my-key-id", } _, err = authConfig.ContextWithValue(context.Background()) - if err == nil || !strings.Contains(err.Error(), "Private key path must be specified") { + if err == nil || !strings.Contains(err.Error(), "private key path must be specified") { t.Fatalf("Invalid configuration: %v", err) } @@ -667,7 +667,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) { PrivateKeyPath: "test.pem", } _, err = authConfig.ContextWithValue(context.Background()) - if err == nil || !strings.Contains(err.Error(), "Invalid signing scheme") { + if err == nil || !strings.Contains(err.Error(), "invalid signing scheme") { t.Fatalf("Invalid configuration: %v", err) } @@ -677,7 +677,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) { SigningScheme: "garbage", } _, err = authConfig.ContextWithValue(context.Background()) - if err == nil || !strings.Contains(err.Error(), "Invalid signing scheme") { + if err == nil || !strings.Contains(err.Error(), "invalid signing scheme") { t.Fatalf("Invalid configuration: %v", err) } @@ -699,7 +699,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) { SignedHeaders: []string{"foo", "bar", "Authorization"}, } _, err = authConfig.ContextWithValue(context.Background()) - if err == nil || !strings.Contains(err.Error(), "Signed headers cannot include the 'Authorization' header") { + if err == nil || !strings.Contains(err.Error(), "signed headers cannot include the 'Authorization' header") { t.Fatalf("Invalid configuration: %v", err) } @@ -711,7 +711,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) { SignatureMaxValidity: -7 * time.Minute, } _, err = authConfig.ContextWithValue(context.Background()) - if err == nil || !strings.Contains(err.Error(), "Signature max validity must be a positive value") { + if err == nil || !strings.Contains(err.Error(), "signature max validity must be a positive value") { t.Fatalf("Invalid configuration: %v", err) } }