diff --git a/config/clients/go/template/api.mustache b/config/clients/go/template/api.mustache index e52df73e..51db597d 100644 --- a/config/clients/go/template/api.mustache +++ b/config/clients/go/template/api.mustache @@ -115,7 +115,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class if a.client.cfg.StoreId == "" { return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("Configuration.StoreId is required and must be specified to call this method") } - if !internalutils.IsWellFormedUlidString(a.client.cfg.StoreId) { + if a.client.cfg.StoreId != "" && !internalutils.IsWellFormedUlidString(a.client.cfg.StoreId) { return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("Configuration.StoreId is invalid") } {{/pathParams.0}} diff --git a/config/clients/go/template/client/client.mustache b/config/clients/go/template/client/client.mustache index bcdfc5b6..822187f9 100644 --- a/config/clients/go/template/client/client.mustache +++ b/config/clients/go/template/client/client.mustache @@ -76,7 +76,7 @@ func NewSdkClient(cfg *ClientConfiguration) (*{{appShortName}}Client, error) { // store id is already validate as part of configuration validation - if cfg.AuthorizationModelId != nil && !internalutils.IsWellFormedUlidString(*cfg.AuthorizationModelId) { + if cfg.AuthorizationModelId != nil && *cfg.AuthorizationModelId != "" && !internalutils.IsWellFormedUlidString(*cfg.AuthorizationModelId) { return nil, FgaInvalidError{param: "AuthorizationModelId", description: "ULID"} } diff --git a/config/clients/go/template/client/client_test.mustache b/config/clients/go/template/client/client_test.mustache index ab2447b7..bcf94e19 100644 --- a/config/clients/go/template/client/client_test.mustache +++ b/config/clients/go/template/client/client_test.mustache @@ -39,6 +39,16 @@ func Test{{appShortName}}Client(t *testing.T) { } }) + t.Run("Allow client to have empty store ID specified", func(t *testing.T){ + _, err := NewSdkClient(&ClientConfiguration{ + ApiHost: "api.fga.example", + StoreId: "", + }) + if err != nil { + t.Fatalf("Expect no error when store id is empty but has %v", err) + } + }) + t.Run("Validate store ID when specified", func(t *testing.T){ _, err := NewSdkClient(&ClientConfiguration{ ApiHost: "api.fga.example", @@ -60,6 +70,18 @@ func Test{{appShortName}}Client(t *testing.T) { } }) + t.Run("Allow auth model ID to be empty when specified", func(t *testing.T){ + _, err := NewSdkClient(&ClientConfiguration{ + ApiHost: "api.fga.example", + StoreId: "01GXSB9YR785C4FYS3C0RTG7B2", + AuthorizationModelId: {{packageName}}.PtrString(""), + }) + if err != nil { + t.Fatalf("Expect no error when auth model id is empty but has %v", err) + } + }) + + /* Stores */ t.Run("ListStores", func(t *testing.T) { test := TestDefinition{