Skip to content

Commit

Permalink
fix(go-sdk): client option + body not respected (#148)
Browse files Browse the repository at this point in the history
Client not taking in details for option and body in list stores/read changes etc.
In addition, read auth model does not check and error when auth model is id string

Close openfga/go-sdk#41
Close openfga/go-sdk#42
  • Loading branch information
adriantam authored Jul 11, 2023
1 parent dd9a1c9 commit b21df73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
27 changes: 16 additions & 11 deletions config/clients/go/template/client/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,11 @@ func (client *{{appShortName}}Client) ListStoresExecute(request SdkClientListSto
req := client.{{appShortName}}Api.ListStores(request.GetContext())
pageSize := getPageSizeFromRequest((*ClientPaginationOptions)(request.GetOptions()))
if pageSize != nil {
req.PageSize(*pageSize)
req = req.PageSize(*pageSize)
}
continuationToken := getContinuationTokenFromRequest((*ClientPaginationOptions)(request.GetOptions()))
if continuationToken != nil {
req.ContinuationToken(*continuationToken)
req = req.ContinuationToken(*continuationToken)
}
data, _, err := req.Execute()
if err != nil {
Expand Down Expand Up @@ -720,11 +720,11 @@ func (client *{{appShortName}}Client) ReadAuthorizationModelsExecute(request Sdk
req := client.{{appShortName}}Api.ReadAuthorizationModels(request.GetContext())
pageSize := getPageSizeFromRequest((*ClientPaginationOptions)(request.GetOptions()))
if pageSize != nil {
req.PageSize(*pageSize)
req = req.PageSize(*pageSize)
}
continuationToken := getContinuationTokenFromRequest((*ClientPaginationOptions)(request.GetOptions()))
if continuationToken != nil {
req.ContinuationToken(*continuationToken)
req = req.ContinuationToken(*continuationToken)
}
data, _, err := req.Execute()
if err != nil {
Expand Down Expand Up @@ -881,7 +881,7 @@ func (client *{{appShortName}}Client) ReadAuthorizationModelExecute(request SdkC
if err != nil {
return nil, err
}
if authorizationModelId == nil {
if authorizationModelId == nil || *authorizationModelId == "" {
return nil, FgaRequiredParamError{param: "AuthorizationModelId"}
}
data, _, err := client.{{appShortName}}Api.ReadAuthorizationModel(request.GetContext(), *authorizationModelId).Execute()
Expand Down Expand Up @@ -1031,12 +1031,17 @@ func (client *{{appShortName}}Client) ReadChangesExecute(request SdkClientReadCh
req := client.{{appShortName}}Api.ReadChanges(request.GetContext())
pageSize := getPageSizeFromRequest((*ClientPaginationOptions)(request.GetOptions()))
if pageSize != nil {
req.PageSize(*pageSize)
req = req.PageSize(*pageSize)
}
continuationToken := getContinuationTokenFromRequest((*ClientPaginationOptions)(request.GetOptions()))
if continuationToken != nil {
req.ContinuationToken(*continuationToken)
req = req.ContinuationToken(*continuationToken)
}
requestBody := request.GetBody()
if requestBody != nil {
req = req.Type_(requestBody.Type)
}

data, _, err := req.Execute()
if err != nil {
return nil, err
Expand Down Expand Up @@ -1479,7 +1484,7 @@ func (client *{{appShortName}}Client) WriteTuplesExecute(request SdkClientWriteT
Writes: request.GetBody(),
})
if request.GetOptions() != nil {
baseReq.Options(*request.GetOptions())
baseReq = baseReq.Options(*request.GetOptions())
}
return baseReq.Execute()
}
Expand Down Expand Up @@ -1543,7 +1548,7 @@ func (client *{{appShortName}}Client) DeleteTuplesExecute(request SdkClientDelet
Deletes: request.GetBody(),
})
if request.GetOptions() != nil {
baseReq.Options(*request.GetOptions())
baseReq = baseReq.Options(*request.GetOptions())
}
return baseReq.Execute()
}
Expand Down Expand Up @@ -2147,7 +2152,7 @@ func (client *{{appShortName}}Client) ReadAssertionsExecute(request SdkClientRea
if err != nil {
return nil, err
}
if authorizationModelId == nil {
if authorizationModelId == nil || *authorizationModelId == "" {
return nil, FgaRequiredParamError{param: "AuthorizationModelId"}
}
data, _, err := client.{{appShortName}}Api.ReadAssertions(request.GetContext(), *authorizationModelId).Execute()
Expand Down Expand Up @@ -2251,7 +2256,7 @@ func (client *{{appShortName}}Client) WriteAssertionsExecute(request SdkClientWr
if err != nil {
return nil, err
}
if authorizationModelId == nil {
if authorizationModelId == nil || *authorizationModelId == "" {
return nil, FgaRequiredParamError{param: "AuthorizationModelId"}
}
for index := 0; index < len(*request.GetBody()); index++ {
Expand Down
10 changes: 9 additions & 1 deletion config/clients/go/template/client/client_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,20 @@ func Test{{appShortName}}Client(t *testing.T) {
if *(*got.AuthorizationModel).Id != modelId {
t.Fatalf("{{appShortName}}Client.%v() = %v, want %v", test.Name, string(responseJson), test.JsonResponse)
}
// ReadAuthorizationModel without options should work
// ReadAuthorizationModel without options should not work
_, err = fgaClient.ReadAuthorizationModel(context.Background()).Execute()
expectedError := "Required parameter AuthorizationModelId was not provided"
if err == nil || err.Error() != expectedError {
t.Fatalf("Expected error:%v, got: %v", expectedError, err)
}
// ReadAuthorizationModel with options of empty string should not work
badOptions := ClientReadAuthorizationModelOptions{
AuthorizationModelId: {{packageName}}.PtrString(""),
}
_, err = fgaClient.ReadAuthorizationModel(context.Background()).Options(badOptions).Execute()
if err == nil || err.Error() != expectedError {
t.Fatalf("Expected error:%v, got: %v", expectedError, err)
}
})

t.Run("ReadLatestAuthorizationModel", func(t *testing.T) {
Expand Down

0 comments on commit b21df73

Please sign in to comment.